Ember CLI testing complicated model relationships

Unit Testingember.jsEmber DataEmber Cli

Unit Testing Problem Overview


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?

Unit Testing Solutions


Solution 1 - Unit Testing

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaquavitaeView Question on Stackoverflow
Solution 1 - Unit TestingMOHIT KUMARView Answer on Stackoverflow