Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember CLI testing complicated model relationships

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?

like image 263
aquavitae Avatar asked Oct 01 '14 09:10

aquavitae


1 Answers

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

like image 158
MOHIT KUMAR Avatar answered Oct 17 '22 08:10

MOHIT KUMAR