github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/helpers/module-for-serializer.js (about) 1 import { getOwner } from '@ember/application'; 2 import { moduleForModel } from 'ember-qunit'; 3 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 4 5 export default function(modelName, description, options = { needs: [] }) { 6 // moduleForModel correctly wires up #Serializer.store, 7 // but module does not. 8 moduleForModel(modelName, description, { 9 unit: true, 10 needs: options.needs, 11 beforeEach() { 12 const model = this.subject(); 13 14 // Initializers don't run automatically in unit tests 15 fragmentSerializerInitializer(getOwner(model)); 16 17 // Reassign the subject to provide the serializer 18 this.subject = () => model.store.serializerFor(modelName); 19 20 // Expose the store as well, since it is a parameter for many serializer methods 21 this.store = model.store; 22 23 if (options.beforeEach) { 24 options.beforeEach.apply(this, arguments); 25 } 26 }, 27 afterEach() { 28 if (options.beforeEach) { 29 options.beforeEach.apply(this, arguments); 30 } 31 }, 32 }); 33 }