Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Created February 28, 2018 18:29
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save samselikoff/b00b5a190321c8236ee0e0fab200bf65 to your computer and use it in GitHub Desktop.
Save samselikoff/b00b5a190321c8236ee0e0fab200bf65 to your computer and use it in GitHub Desktop.
// tests/helpers/push-mirage-db-into-store.js
import { registerAsyncHelper } from '@ember/test';
import { run } from '@ember/runloop';
let pushMirageDbIntoStore = function(server, store) {
let tables = Object.keys(server.schema);
tables.forEach(table => {
if (server.schema[table].all) {
let all = server.schema[table].all();
let modelName = all.modelName;
let serializer = server.serializerOrRegistry
.serializerFor(modelName);
let originalAlwaysIncludeLinkageData = serializer.alwaysIncludeLinkageData;
serializer.alwaysIncludeLinkageData = true;
let json = serializer.serialize(all);
serializer.alwaysIncludeLinkageData = originalAlwaysIncludeLinkageData;
run(() => {
store.pushPayload(json);
});
}
});
}
export { pushMirageDbIntoStore };
export default registerAsyncHelper('pushMirageDbIntoStore', function(app) {
let store = app.__container__.lookup('service:store');
return pushMirageDbIntoStore(server, store);
});
@bbansalWolfPack
Copy link

Thanks Sam for sharing this file. Do you have an example where I can see a unit test using this? I created the helper and seeded my mirage (using the link you gave earlier) but then when I do this.subject(), it does not give me the store model back and in fact looking for store service and doing peekAll does not show any records created.

I am new to Ember so does not have much idea. Will appreciate if you can help.

@Mifrill
Copy link

Mifrill commented Nov 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment