gpt4 book ai didi

javascript - “等于”未定义 : Ember-qunit does not seem to be importing

转载 作者:数据小太阳 更新时间:2023-10-29 05:54:40 25 4
gpt4 key购买 nike

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

最佳答案

作者在这里!抱歉,我实际上需要更新代码,因为在最新版本中,测试语法已更改以匹配即将推出的 QUNit 版本。

现在要使用:equalok 和其他 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');
});

关于javascript - “等于”未定义 : Ember-qunit does not seem to be importing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28702390/

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