mercredi 4 février 2015

Component Not Rendering Correctly During Test

I'm writing integration tests for my Ember CLI app, and one of my tests fails every time. This is my current test:



// tests/integration/project-test.js
test('displays "Projects" when the user views a project from Collaborate', function() {
visit('/collaborate');

click('.table > tbody > tr > td > a'); // it goes to /collaborate/projects/:id
expect(0);
});


When it navigates to /collaborate/projects/:id, I get the error "Cannot read property 'setLegend' of null." I traced that to my component:



// app/components/foo-comp.js
import Ember from "ember";

export default Ember.Component.extend({
fooObject: null,
didInsertElement: function () {
var foo = new Foo();

this.set('fooObject', foo);
Ember.run.once(this, 'updateChart');
},
updateChart: function () {
var foo = this.get('fooObject');
foo.setLegend(); // this is where the error comes from
}.observes('data','fooObject')
});


Note that the test does pass if I change updateChart to:



updateChart: function () {
var foo = this.get('fooObject');

if (foo) {
foo.setLegend();
}
}.observes('data','fooObject')


Why would it not set that variable during a test? It works fine in development and production, so I'm not sure why this is happening. I'm assuming it's because didInsertElement isn't triggered when the test runs. Thoughts? Ideas?


Ember version:



version: 0.1.12
node: 0.10.33
npm: 2.1.8




Aucun commentaire:

Enregistrer un commentaire