Testing data model ember data - cannot find a relationship

I try to check the model relationship in the ember-cli application, but he continues to tell me: No models were found for "rateType" . It seems that he cannot find my models.

Files

~app/models/account.js ~app/models/rate-type.js 

Account model

 export default DS.Model.extend({ ... rateType: DS.belongsTo('rateType'), }); 

Test

 import Ember from 'ember'; import { test, moduleForModel } from 'ember-qunit'; import Account from 'app/models/account'; import RateType from 'app/models/rate-type'; moduleForModel('account', 'Account Model', { // Specify the other units that are required for this test. needs: ['model:rate-type'] }); test('rateType relationship', function() { expect(0); this.subject(); //error here // var relationships = Ember.get(Account, 'relationships'); // deepEqual(relationships.get('rate-type'), [ // { name: 'rateType', kind: 'belongsTo' } // ]); }); 

I tried a camel shell, but I don’t like it at all. needs: ['model:rateType', 'model:fuelGroup']

+7
ember-cli ember-data ember-qunit
source share
2 answers

I think you need the needs keyword:

 moduleForModel('post', 'Unit | Model | post', { needs: ['model:comment', 'model:user'] }); 

I found it in the docs here: http://guides.emberjs.com/v1.10.0/testing/testing-models/

+11
source share

Your problem is with the model. Try dasherizing 'rate-type' in the belongsTo property.

 export default DS.Model.extend({ ... rateType: DS.belongsTo('rate-type') }); 
+3
source share

All Articles