首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ember模型测试失败

Ember模型测试失败
EN

Stack Overflow用户
提问于 2015-08-22 08:47:56
回答 1查看 35关注 0票数 0

嗨,我正试着用Ember CLI写第一批测试。这就是我的测试

代码语言:javascript
复制
> ...
> 
> 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); });

以及模型配方/配方模型

代码语言:javascript
复制
...
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'},
    ]
});

如果我运行给定的测试,它会输出:错误:没有找到“食谱/类别”的模型

如果我评论//类别和//文件的模型。测试通过了。目前使用的是夹具适配器。当我创建记录或将它们加载到应用程序的工作流中时,所有的关系都可以正常工作。(比如store.find(‘食谱/类别’)等等)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-22 10:22:04

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

代码语言:javascript
复制
needs: ['model:recipe/recipe', 'model:recipe/category', 'model:filerepository/file']
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32154195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档