“尝试注册未知工厂”在模型试验中 [英] "Attempting to register an unknown factory" in model test
问题描述
var PuzzleRound = DS.Model.extend({
年:DS.attr('number')
});
var Puzzle = DS.Model.extend({
puzzleRounds:DS.hasMany('puzzleRound',{async:true})
});
这是我从 tests / unit / models / puzzle-test的测试。 js
:
import {
moduleForModel,
test
}从'ember-qunit';
导入PuzzleRound从'weather-roulette / models / puzzle-round';
moduleForModel('puzzle','Puzzle',{
//指定此测试所需的其他单位
需要:['model:puzzleRound']
});
test('it exists',function(){
var model = this.subject();
// var store = this.store();
ok(!! model);
});
运行 ember测试
时,我收到此错误:
尝试注册一个未知工厂:`model:puzzleRound`
pre>
我使用的是ember-cli 0.1.1,Ember.js 1.7.0,Ember Data 1.0.0-beta.11。有没有人可以尝试解决这个问题?
解决方案我刚刚尝试了这个代码与ember-cli 0.0.44和我得到了同样的错误。
我将这两个引用重命名为
puzzleRound
模型路径到puzzle-round
然后你的测试通过了我。所以:DS.Model.extend({
puzzleRounds:DS.hasMany('puzzle-round',{ async:true})
});
和
moduleForModel('puzzle','Puzzle',{
需要:['model:puzzle-round']
});
我知道连字样式优于camelCase样式,但我不知道这个成为强制性这个要求可能是特定于ember-cli或ember-qunit。
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?
解决方案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 topuzzle-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.
这篇关于“尝试注册未知工厂”在模型试验中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!