As far as I can see, when testing ember-data models in ember CLI, all relationships have to be listed in needs
. This is fine if the structure is simple, but in many cases there will be multiple layers.
For example, if models are set up with the following relationships defined:
Model a:
belongsTo: b
belongsTo: c
Model b:
hasMany: a
hasMany: d
Model c:
hasMany: a
belongsTo: e
Model d:
hasMany b
Model e:
hasMany c
Then every unit test for any of these models will require every other model listed in needs
, e.g. A test for c
:
needs: [
'model:a' // Because c -> a
'model:e' // Because c -> e
'model:b' // Because c -> a -> b
'model:d' // Because c -> a -> b -> d
]
My actual configuration is a lot more complicated with 14 models, and each one indirectly related to all the others.
Is my understanding correct? Is there a more efficient way of doing this? Or is there a good reason for doing it this way that I am missing?
If you are using Ember default 'Ember-QUnit' then you have to list all the models in needs.
But there is an alternative for testing which I am using i.e. ember-data-factory-guy. This is used to create factory instead of fixture data when testing Model, component, controller etc.
You can go through it.
https://github.com/danielspaniel/ember-data-factory-guy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With