nny*_*yby 5 ember.js ember-data ember-cli ember-qunit
我在ember-cli应用程序中有这些模型:
var PuzzleRound = DS.Model.extend({
year: DS.attr('number')
});
var Puzzle = DS.Model.extend({
puzzleRounds: DS.hasMany('puzzleRound', {async: true})
});
Run Code Online (Sandbox Code Playgroud)
这是我的测试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);
});
Run Code Online (Sandbox Code Playgroud)
运行时出现此错误ember test:
Attempting to register an unknown factory: `model:puzzleRound`
Run Code Online (Sandbox Code Playgroud)
我使用的是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})
});
Run Code Online (Sandbox Code Playgroud)
和
moduleForModel('puzzle', 'Puzzle', {
needs: ['model:puzzle-round']
});
Run Code Online (Sandbox Code Playgroud)
我知道连字符样式比驼峰样式更受青睐,但我不确定这何时成为强制性的。此要求可能特定于 ember-cli 或 ember-qunit。