open-nomad/ui/tests/helpers/module-for-adapter.js

34 lines
1 KiB
JavaScript
Raw Normal View History

import { getOwner } from '@ember/application';
import { moduleForModel } from 'ember-qunit';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
export default function(modelName, description, options = { needs: [] }) {
// moduleForModel correctly creates the store service
// but moduleFor does not.
moduleForModel(modelName, description, {
unit: true,
needs: options.needs,
beforeEach() {
const model = this.subject();
// Initializers don't run automatically in unit tests
fragmentSerializerInitializer(getOwner(model));
// Reassign the subject to provide the adapter
this.subject = () => model.store.adapterFor(modelName);
// Expose the store as well, since it is a parameter for many adapter methods
this.store = model.store;
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
2018-03-01 00:34:27 +00:00
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
},
});
}