"Attempt to register an unknown factory" in a model test

I have these models in an ember-cli application:

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

And here is 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 am using ember-cli 0.1.1, Ember.js 1.7.0, Ember Data 1.0.0-beta.11. Anyone have anything that I can try to fix?

+5
source share
2 answers

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

I renamed both links to the puzzleRound model puzzleRound 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 hyphen style was preferable to the camelCase style, but I'm not sure when it became mandatory. This requirement may be specific to ember-cli or ember-qunit.

+3
source

I was looking for some solution like this for a while, and did not see any mention of my solution, so I thought that I would post here anyway. It is very simple: make sure that the controller you are referring to is actually there.

 // my-ember-application/tests/unit/controllers/index/bar-test.js moduleFor('controller:index/bar', 'My Bar Test', { beforeEach() { .. } }); test('it exists', function (assert) { assert.ok(true); }); 

This code will refer to the controller in this place:

my-ember-application/app/controllers/index/bar.js

0
source

Source: https://habr.com/ru/post/1204592/


All Articles