Created
February 28, 2018 18:29
-
-
Save samselikoff/b00b5a190321c8236ee0e0fab200bf65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
Thank you!
Source of issue: https://stackoverflow.com/questions/51193119/ember-mirage-not-passing-model-as-an-ember-object
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.