2014-10-13 13 views
5

Ho questi modelli in un app brace-cli:"Tentativo di registrare una fabbrica sconosciuta" in prova il modello

var PuzzleRound = DS.Model.extend({ 
    year: DS.attr('number') 
}); 

var Puzzle = DS.Model.extend({ 
    puzzleRounds: DS.hasMany('puzzleRound', {async: true}) 
}); 

Ed ecco la mia prova da tests/unit/models/puzzle-test.js:

import { 
    moduleForModel, 
    test 
} from 'ember-qunit'; 
import PuzzleRound from 'weather-roulette/models/puzzle-round'; 

moduleForModel('puzzle', 'Puzzle', { 
    // Specify the other units that are required for this test. 
    needs: ['model:puzzleRound'] 
}); 

test('it exists', function() { 
    var model = this.subject(); 
    // var store = this.store();  
    ok(!!model);    
}); 

ottengo questo errore durante l'esecuzione ember test:

Attempting to register an unknown factory: `model:puzzleRound` 

sto usando brace-cli 0.1.1, 1.7.0 Ember.js, Emb er Data 1.0.0-beta.11. Qualcuno ha qualcosa che posso provare a risolvere questo?

risposta

3

Ho appena provato questo codice con ember-cli 0.0.44 e ho ottenuto lo stesso errore che hai fatto.

Ho rinominato entrambi i riferimenti al percorso del modello puzzleRound a puzzle-round e quindi il test è passato per me. Quindi:

DS.Model.extend({ 
    puzzleRounds: DS.hasMany('puzzle-round', {async: true}) 
}); 

e

moduleForModel('puzzle', 'Puzzle', { 
    needs: ['model:puzzle-round'] 
}); 

Sapevo che lo stile con trattino è stato preferito lo stile camelCase, ma non sono sicuro che quando questo è diventato obbligatorio. Questo requisito può essere specifico per ember-cli o ember-qunit.

0

Stavo cercando una soluzione simile a questa per un po ', e non ho visto alcuna menzione della mia soluzione, quindi ho pensato di postare qui comunque. In realtà è abbastanza semplice: assicurati che il controller a cui fai riferimento sia effettivamente lì.

// my-ember-application/tests/unit/controllers/index/bar-test.js 
moduleFor('controller:index/bar', 'My Bar Test', { 
    beforeEach() { .. } 
}); 

test('it exists', function (assert) { 
    assert.ok(true); 
}); 

Questo codice riferimento a un controllore in questa posizione:

my-ember-application/app/controllers/index/bar.js

Problemi correlati