gpt4 book ai didi

ember.js - 模型测试中"Attempting to register an unknown factory"

转载 作者:行者123 更新时间:2023-12-02 21:48:54 24 4
gpt4 key购买 nike

我在 ember-cli 应用程序中有这些模型:

var PuzzleRound = DS.Model.extend({
year: DS.attr('number')
});

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

这是我来自 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);
});

运行ember test时出现此错误:

Attempting to register an unknown factory: `model:puzzleRound`

我正在使用 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', {
needs: ['model:puzzle-round']
});

我知道连字符样式比驼峰样式更受青睐,但我不确定这何时成为强制性的。此要求可能特定于 ember-cli 或 ember-qunit。

关于ember.js - 模型测试中"Attempting to register an unknown factory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com