Sto provando a fare un test di base "funziona" per un Mixin che deve essere utilizzato con un Modello. Suppongo che l'approccio al test unitario debba essere fatto non sul Mixin stesso ma su una generica classe di modello con questo mixin miscelato.Unit test a Model Mixin
Supponendo che questa prima ipotesi/strategia abbia senso, ecco cosa ho provato a fare:
import DS from 'ember-data';
import Ember from 'ember';
import DictionaryManagerMixin from 'trainer/mixins/dictionary-manager';
module('DictionaryManagerMixin');
test('it works', function() {
var DictionaryManagerModel = DS.Model.extend(DictionaryManagerMixin, {
title: DS.attr('string')
});
var myStore = DS.Store.create();
var subject = myStore.createRecord(DictionaryManagerModel);
ok(subject);
});
Questo non funziona, dando il seguente errore:
TypeError: Cannot read property 'lookup' of undefined
at null.<anonymous> (http://localhost:4200/assets/vendor.js:95610:35)
at Descriptor.ComputedPropertyPrototype.get (http://localhost:4200/assets/vendor.js:28466:25)
at get (http://localhost:4200/assets/vendor.js:33944:21)
at Ember.Object.extend.adapterFor (http://localhost:4200/assets/vendor.js:97005:27)
at Ember.Object.extend._generateId (http://localhost:4200/assets/vendor.js:95682:28)
at Ember.Object.extend.createRecord (http://localhost:4200/assets/vendor.js:95654:32)
at Object.eval (trainer/tests/unit/mixins/dictionary-manager-test.js:17:28)
at Object.Test.run (http://localhost:4200/assets/test-support.js:2632:18)
at http://localhost:4200/assets/test-support.js:2719:10
at process (http://localhost:4200/assets/test-support.js:2435:24)
Qualsiasi aiuto sarebbe molto apprezzato.
Sto facendo lo stesso, ma utilizzando il mixin come unità da testare invece di testare il modello. Se usi ember-cli, quando generi "mixin" crea il test per te – leojh