【问题标题】:Ember CLI model testing failsEmber CLI 模型测试失败
【发布时间】:2015-11-16 05:13:22
【问题描述】:

您好,我正在尝试在 Ember CLI 中编写第一个测试。这就是我的测试的样子

> ...
> 
> moduleForModel('recipe/recipe', 'Recipe Model works', {
>     needs: ['model:recipe/recipe'] });
>        test('Recipe is a valid ember-data Model', function (assert) {
>     var store = this.store();
>     var recipe = this.subject({name: 'A title for a recipe'});
>     
>     assert.ok(recipe instanceof DS.Model); });

还有模型配方/配方模型

...
var Recipe = DS.Model.extend({
    name: DS.attr('string'),

    category: DS.belongsTo('recipe/category', {async: true}),
    file: DS.belongsTo('filerepository/file', {async: true})
});

Recipe.reopenClass({
    FIXTURES: [
        { id: 1, name: 'New Recipe'},
    ]
});

如果我运行给定的测试,它会输出:错误:找不到'recipe/category'的模型

如果我在模型上评论 //category 和 //file。测试通过。目前使用夹具适配器。当我创建记录或将它们加载到应用程序的工作流程中时,所有关系都可以正常工作。 (如 store.find('recipe/category') 等)

【问题讨论】:

    标签: ember.js ember-cli ember-qunit


    【解决方案1】:

    你需要在moduleForModel中声明更多你依赖的模型:

    needs: ['model:recipe/recipe', 'model:recipe/category', 'model:filerepository/file']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      相关资源
      最近更新 更多