Skip to content

Instantly share code, notes, and snippets.

@jeradg
Created March 3, 2016 19:46
Show Gist options
  • Save jeradg/6f8bfbbf0722d34eea09 to your computer and use it in GitHub Desktop.
Save jeradg/6f8bfbbf0722d34eea09 to your computer and use it in GitHub Desktop.
Mock ember-data object factory - Use mirage fixtures (or any other plain old JS object) to mock Ember Data models in component integration tests. See also ember-cli-mirage-object-factory.js - https://gist.github.com/jeradg/6043ba31d831633ce4e3
// tests/helpers/model-mock.js
export function modelMock(attrs) {
const emberDataRecordAttrs = {
isValid: true,
isNew: false
};
return Ember.Object.extend(emberDataRecordAttrs)
.create(attrs);
}
// In your integration test.
// fixtureArray just exports an array of POJOs.
import fixtureArray from 'frontend/mirage/fixtures/something';
import modelMock from 'frontend/tests/helpers/model-mock';
const something = modelMock(fixtureArray[0]);
this.set('model', something);
this.render(hbs`{{my-component model=model}}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment