ember-cli-mirage: JSON API setup doesn't return JSON API documents?
I have this query in my route:
let promise = this.get('store').findRecord('host', subdomain, {
adapterOptions: {
query: {
subdomain: subdomain
},
},
});
and this in my tests:
let org = server.create('organization', {
name: 'Test Org',
domain: 'testorg'
});
server.get('api/hosts/testorg', org);
I (hopefully) specified to use the JSON API serializer?
// mirage/serializers/application.js
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer;
so, when I run my test, I get this error:
"Assertion Failed: normalizeResponse must return a valid JSON API document: * One or more of the following keys must be present: "data", "errors", "meta"."
implying that data, errors, or meta are not present.
This is when I’m inspecting the reason parameter of the error action in my route. I don’t know how to actually see the payload. (the transition object doesn’t appear to have anything useful either)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15
Oh, I see the problem. You’re writing
so you’re just returning the raw
dbrecord, which doesn’t get serialized. To use the serialize you need to return a Model or Collection. This should beYou’ll probably get an error, then, because it looks like you don’t have your models defined. Try
ember g mirage-model organization.hey after I ran
ember g mirage-model organizationmy test passed!!! thank you!!! 😃Looks like it’s not going through the serializer layer, have you set up JSONAPISerializer in
mirage/serializers/application.js?