'equal' is not defined : Ember-qunit does not seem to be importing

守給你的承諾、 提交于 2019-12-05 09:07:18

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.

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');
});

Look in tests/helpers/start-app.js. You should see something like:

Ember.run(function() {
    registerAcceptanceTestHelpers();
    application = Application.create(attributes);
    application.setupForTesting();
    application.injectTestHelpers();
  });

This injects the test helpers into the application global scope.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!