200 200 200 200 X- 200 200 X- 200 X- 20045 X- 20045 X-4545 X-4545ECEColololEC X- [英] 'equal' is not defined : Ember-qunit does not seem to be importing
问题描述
似乎Qunit测试方法不可用,即使我很确定正确导入它们。
It appears the Qunit test methods aren't available even though I'm pretty sure I am importing them correctly.
我收到以下错误:
unit/models/friend-test.js: line 11, col 3, 'ok' is not defined.
unit/models/friend-test.js: line 17, col 3, 'equal' is not defined.
unit/models/friend-test.js: line 23, col 3, 'equal' is not defined.
unit/models/friend-test.js: line 31, col 3, 'equal' is not defined.
unit/models/friend-test.js: line 32, col 3, 'equal' is not defined.
我有这个测试文件 unit / models / friend-test
:
import Ember from 'ember';
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('friend', 'Friend', {
needs: ['model:article']
});
test('it exists', function() {
var model = this.subject();
ok(model);
});
test('fullName concats first and last name', function() {
var model = this.subject({firstName: 'Syd', lastName: 'Barrett'});
equal(model.get('fullName'), 'Syd Barrett');
Ember.run(function() {
model.set('firstName', 'Geddy');
});
equal(model.get('fullName'), 'Geddy Barrett', 'Updates fullName');
});
test('articles relationship', function() {
var klass = this.subject({}).constructor;
var relationship = Ember.get(klass, 'relationshipsByName').get('articles');
equal(relationship.key, 'articles');
equal(relationship.kind, 'hasMany');
});
我正在通过 Ember CLI 101
推荐答案
很抱歉,我实际上需要更新代码,因为在最新版本上,测试的语法更改为与即将发布的QUNit版本相匹配。
Author here! Sorry about it, I actually need to update the code since on the latest release the syntax for tests changed to match the upcoming version of QUNit.
现在使用:等于
, ok
和其他QUnit的断言,我们必须通过在传递给测试的回调函数中称为assert的param :
test('foo',function(assert){assert.ok(true)}
。我今晚将发送一本书更新来修复这个:)在此期间,以下内容应该起作用:
Now to use: equal
, ok
and the other QUnit's assertions, we have to do it through a param called assert in the callback function passed to test:
test('foo', function(assert){ assert.ok(true) }
. I'll send a book update tonight to fix this :), in the meantime, the following should work:
import Ember from 'ember';
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('friend', 'Friend', {
needs: ['model:article']
});
test('it exists', function(assert) {
var model = this.subject();
assert.ok(model);
});
test('fullName concats first and last name', function(assert) {
var model = this.subject({firstName: 'Syd', lastName: 'Barrett'});
equal(model.get('fullName'), 'Syd Barrett');
Ember.run(function(assert) {
model.set('firstName', 'Geddy');
});
assert.equal(model.get('fullName'), 'Geddy Barrett', 'Updates fullName');
});
test('articles relationship', function(assert) {
var klass = this.subject({}).constructor;
var relationship = Ember.get(klass, 'relationshipsByName').get('articles');
assert.equal(relationship.key, 'articles');
assert.equal(relationship.kind, 'hasMany');
});
这篇关于200 200 200 200 X- 200 200 X- 200 X- 20045 X- 20045 X-4545 X-4545ECEColololEC X-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!