I'm trying to setup mirage on a new app for testing.
ember-cli: 2.16.2
ember-cli-mirage: 0.4.0
I have a dummy test, just trying to setup mirage and verify it's working. I would do something similar to test route.model()
. Using mirage's JSONAPISerializer
, nothing in my factory and migrage-model.
// models/trip.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
});
My test :
import {moduleFor, test} from 'ember-qunit';
import {startMirage} from 'frontend/initializers/ember-cli-mirage';
moduleFor('route:trips.index', 'Unit | Route | trips.index', {
needs: ['service:session', 'model:trip', 'adapter:application'],
beforeEach() {
this.server = startMirage();
},
afterEach() {
this.server.shutdown();
}
});
test('model', function (assert) {
let route = this.subject();
this.server.create('trip');
Ember.run(() => {
this.get('store').findAll('trip')
});
assert.ok(route);
});
I get this error:
TypeError: Cannot read property 'push' of null
at Class._setupRelationshipsForModel
Works fine on development/production and using a real server to get the data.
If i dont create my record with mirage, there is no exception.
Looks like the problem only occurs within Ember.run
This will not raise the exception, but I think I need Ember.run
to test properly...
test('model', function (assert) {
let route = this.subject();
this.server.create('trip');
this.get('store').findAll('trip')
assert.ok(route);
});
Aucun commentaire:
Enregistrer un commentaire