Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember-cli unit tests with relationships 'needs'

I am working on my unit tests and it feels like I am doing something incorrect. I have a 'main' object that has many relationships

author: belongsTo('person', { async: true }),
title: attr('string'),
category: belongsTo('category', { async: true }),
impact: belongsTo('impact', { async: true }),
status: attr('string'),
createdDate: attr('moment'),
submittedDate: attr('moment'),
authorOrg: belongsTo('organization', { async: true }),
locations: hasMany('location', { async: true }),
audits: hasMany('audit', { async: true })

And each time I work on the unit tests for its related items (person, category,impact), I'm having to reproduce all of the needs values that my 'main' object has. It just doesn't feel right for my location unit test to need category when it only cares about a string for its name and its relationship back to the 'main' object

// location/model-test.js
import {
  moduleForModel,
  test
} from 'ember-qunit';

moduleForModel('location', 'Location', {
  // Specify the other units that are required for this test.
  needs: ['model:main', 'model:person', 'model:category',
      'model:impact', 'model:organization', 'model:location']
});

Am I doing something wrong or is there a better way to build my unit tests to deal with the relationships?

I am on ember-cli 0.1.5, ember 1.9.1, and ember-data beta 14

like image 274
RyanHirsch Avatar asked Jan 05 '15 22:01

RyanHirsch


1 Answers

I have resorted to defining a wrapper function that adds a specifier to the module label and then I use this convenience function each time I want a new module:

var anotherModule = function(suffix) {
  moduleForModel('location', 'Location - ' + suffix, {
    needs: ['model:main', 'model:person', 'model:category',
      'model:impact', 'model:organization', 'model:location']
  });
};

anotherModule("module 1");
test("test 1.1", function() { });
test("test 1.1", function() { });

anotherModule("module 2");
test("test 2.1", function() { });
like image 171
Kevin Bullaughey Avatar answered Sep 29 '22 20:09

Kevin Bullaughey