Ember-cli : relationship unit test for model failing


Hi, I am using Ember-cli and qunit for testing.

Item Model

import DS from 'ember-data';
var attr = DS.attr,
    belongsTo = DS.belongsTo;

export default DS.Model.extend({
  offer: belongsTo('offer'),

Here am adding test for relation between item and Offer model.

Item Tests

import Ember from "ember";
import DS from "ember-data";
import { test, moduleForModel } from 'ember-qunit';

moduleForModel('item', 'Item Model', {
  needs: ['model:item']

test('offer relationship', function() {
  var relationships = Ember.get(App.Item, 'relationships');
  deepEqual(relationships.get(App.Offer), [
    { name: 'offer', kind: 'belongsTo' }

Error Trace:

Died on test #1     at test (http://localhost:4200/assets/vendor.js:73836:13)
    at eval (goodcity/tests/unit/item-test.js:44:5)
    at requireModule (http://localhost:4200/assets/vendor.js:54:29)
    at http://localhost:4200/assets/test-loader.js:14:29: App is not defined
ReferenceError: App is not defined
    at Object.eval (goodcity/tests/unit/item-test.js:45:37)
    at Object.wrapper (http://localhost:4200/assets/vendor.js:73824:31)
    at Object.Test.run (http://localhost:4200/assets/qunit.js:203:18)
    at http://localhost:4200/assets/qunit.js:361:10
    at process (http://localhost:4200/assets/qunit.js:1453:24)
    at http://localhost:4200/assets/qunit.js:479:5

Am i missing something?


When you use “moduleForModel” you aren’t ever creating an instance of your app. So nothing is being defined as App. If you need your app you can create on by having a setup: function(){...} placed after “needs”.

You are creating a model for “item” so you don’t need it (needs: ['model:item]) you should write: needs: ['model:offer']