'equal' 未定义:Ember-qunit 似乎未导入
'equal' is not defined : Ember-qunit does not seem to be importing
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”
查看tests/helpers/start-app.js。您应该会看到如下内容:
Ember.run(function() {
registerAcceptanceTestHelpers();
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
这会将测试助手注入应用程序全局范围。
作者在这里!抱歉,我实际上需要更新代码,因为在最新版本中,测试语法已更改以匹配即将推出的 QUNit 版本。
现在要使用:equal
、ok
和其他 QUnit 的断言,我们必须通过传递给测试的回调函数中名为 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');
});
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”
查看tests/helpers/start-app.js。您应该会看到如下内容:
Ember.run(function() {
registerAcceptanceTestHelpers();
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
这会将测试助手注入应用程序全局范围。
作者在这里!抱歉,我实际上需要更新代码,因为在最新版本中,测试语法已更改以匹配即将推出的 QUNit 版本。
现在要使用:equal
、ok
和其他 QUnit 的断言,我们必须通过传递给测试的回调函数中名为 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');
});