Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Attempting to register an unknown factory" in model test

I have these models in an ember-cli app:

var PuzzleRound = DS.Model.extend({
    year: DS.attr('number')
});

var Puzzle = DS.Model.extend({
    puzzleRounds: DS.hasMany('puzzleRound', {async: true})
});

And here's my test from tests/unit/models/puzzle-test.js:

import {
    moduleForModel,
    test
} from 'ember-qunit';
import PuzzleRound from 'weather-roulette/models/puzzle-round';

moduleForModel('puzzle', 'Puzzle', {
    // Specify the other units that are required for this test.
    needs: ['model:puzzleRound']
});

test('it exists', function() {
    var model = this.subject();
    // var store = this.store();    
    ok(!!model);               
});

I get this error when running ember test:

Attempting to register an unknown factory: `model:puzzleRound`

I'm using ember-cli 0.1.1, Ember.js 1.7.0, Ember Data 1.0.0-beta.11. Does anyone have anything I can try to fix this?

like image 464
nnyby Avatar asked Oct 21 '22 00:10

nnyby


1 Answers

I just tried out this code with ember-cli 0.0.44 and I got the same error that you did.

I renamed both references to the puzzleRound model path to puzzle-round and then your test passed for me. So:

DS.Model.extend({
  puzzleRounds: DS.hasMany('puzzle-round', {async: true})
});

and

moduleForModel('puzzle', 'Puzzle', {
  needs: ['model:puzzle-round']
});

I knew that the hyphenated style was preferred over the camelCase style, but I'm not sure when this became mandatory. This requirement may be specific to ember-cli or ember-qunit.

like image 59
Mitch Avatar answered Oct 29 '22 23:10

Mitch