2015-01-05 17 views
11

Ich arbeite an meinen Unit-Tests und es fühlt sich an, als ob ich etwas falsch mache. Ich habe ein ‚Haupt‘ Objekt, das viele BeziehungenEmber-Cli-Unit-Tests mit Beziehungen "Bedürfnisse"

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 }) 

Und jedes Mal, wenn ich die Arbeit an den Unit-Tests für seinen zugehörigen Artikel (person, category, impact) hat, ich habe all die needs Werte zu reproduzieren das hat mein "Haupt" -Objekt. Es fühlt sich einfach nicht richtig für meine Lage Unit-Test category müssen, wenn es nur um eine Zeichenfolge für seinen Namen und seine Beziehung zum ‚Haupt‘ Objekt kümmert sich zurück

// 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'] 
}); 

Bin ich etwas falsch zu machen oder gibt es eine bessere Möglichkeit, meine Komponententests zu erstellen, um mit den Beziehungen umzugehen?

Ich bin auf glut-cli 0.1.5, 1.9.1 Ember und glut-Daten Beta 14

Antwort

1

I, die eine Wrapper-Funktion zurückgegriffen haben, die einen Bezeichner an das Modul Etikett ergänzt und dann verwende ich diese Komfortfunktion jedes Mal, wenn ich ein neues Modul möchte:

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() { }); 
Verwandte Themen