"equal" is not defined: Ember-qunit does not seem to import

Qunit testing methods do not seem to be available, although I'm sure I import them correctly.

I get the following errors:

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. 

I have this unit/models/friend-test test file:

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

I work through Ember CLI 101

+5
source share
2 answers

The author is here! Sorry, I actually need to update the code, as in the latest version the test syntax has changed in accordance with the upcoming version of QUNit.

Now, to use: equal , ok and other QUnit statements, we need to do this through a parameter called assert in the callback function passed to test: test('foo', function(assert){ assert.ok(true) } . Today I will send an update to the book to fix this :), meanwhile 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'); }); 
+10
source

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

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

This introduces test assistants to the global application area.

0
source

All Articles