Reputation: 1153
I have three entities Token - N:1 - User - N:1 - Company
. I let ember-cli to generate model tests and all of them failed. Thats somehow expected, since when testing Token it should need User so I added user into needs. Whats mysterious to me is why do I have to include Company as well? Will I have to include all of my models in every model test?
// tests/unit/models/token-test.js
import {moduleForModel, test} from 'ember-qunit';
moduleForModel('token', {
needs: ['model:user', 'model:company']
});
test('it exists', function(assert) {
var model = this.subject();
// var store = this.store();
assert.ok(!!model);
});
//models/token.js
user: DS.belongsTo('user')
//models/user.js
tokens: DS.hasMany('token')
company: DS.belongsTo('company')
//models/company.js
users: DS.hasMany('user')
Upvotes: 0
Views: 555
Reputation: 37369
Without seeing your model definitions I can't know for sure (would you mind posting those?), but it seems like it's because your models have relationships between them. From the Ember CLI website:
Note: If the model you are testing has relationships to any other model, those must be specified through the needs property.
My guess is that your token
model has relationships to both your user
and company
models. (Or your token
is related to the user
, and the user
is related to the company
.)
Ember CLI's goal for tests is for them to be as isolated as possible, so it doesn't load anything for you - you have to declare all dependencies. It seems like a pain, but it makes for much better unit tests.
Upvotes: 2