即使我确定我正确地导入它们,Qunit测试方法似乎也无法使用。
我收到以下错误:
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"
答案 0 :(得分:10)
作者在这里!对不起,我实际上需要更新代码,因为在最新版本中,测试语法已更改,以匹配即将推出的QUNit版本。
现在使用:equal
,ok
和其他QUnit的断言,我们必须通过传递给test的回调函数中的一个名为assert的参数来完成:
test('foo', function(assert){ assert.ok(true) }
。我今晚会发送一本书来更新这个:),同时,以下内容应该有效:
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');
});
答案 1 :(得分:0)
查看tests / helpers / start-app.js。你应该看到类似的东西:
Ember.run(function() {
registerAcceptanceTestHelpers();
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
这会将测试助手注入应用程序全局范围。