Created
March 3, 2016 19:46
-
-
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
This file contains 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/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