9

I am trying to test a model relationship in an ember-cli application but it keeps telling me: No model was found for 'rateType'. It appears that it can't 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 have tried camel casing the needs attribute butit does not like that at all. needs: ['model:rateType', 'model:fuelGroup']

Cameron
  • 2,805
  • 3
  • 31
  • 45
jax
  • 37,735
  • 57
  • 182
  • 278

2 Answers2

13

I think what you need is 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/

Animal Rights
  • 9,107
  • 6
  • 28
  • 40
3

Your issue is with the model. Try dasherizing 'rate-type' in the belongsTo relationship.

export default DS.Model.extend({
    ...
    rateType: DS.belongsTo('rate-type')
});
jheth
  • 380
  • 1
  • 8