The generated test for the component articles/article-row fails with the message "article is null". This is not strictly an error in the book, but it can confuse some people, and existing online documentation doesn't seem to cover this well.
There are actually two problems. First, the component requires an article instance to work, but the test initializes the component without providing an article. A simple fix is to provide a mock article. For example:
var article = Ember.Object.create();
var component = this.subject({article});
This will fix the initial problem, but a new one will arise: the component requires the formatted-date helper to work. Therefore this has to be specified in the needs argument to module For Component:
needs: ['helper:formatted-date'],
The following is a complete, working example:
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
moduleForComponent('articles/article-row', 'Unit | Component | articles/article row', {
needs: ['helper:formatted-date'],
unit: true
});
test('it renders', function(assert) {
assert.expect(2);
var article = Ember.Object.create();
// Creates the component instance
var component = this.subject({article});
assert.equal(component._state, 'preRender');
// Renders the component to the page
this.render();
assert.equal(component._state, 'inDOM');
});
The generated test for the component articles/article-row fails with the message "article is null". This is not strictly an error in the book, but it can confuse some people, and existing online documentation doesn't seem to cover this well.
There are actually two problems. First, the component requires an article instance to work, but the test initializes the component without providing an article. A simple fix is to provide a mock article. For example:
This will fix the initial problem, but a new one will arise: the component requires the formatted-date helper to work. Therefore this has to be specified in the
needs
argument to module For Component:The following is a complete, working example: