Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active January 18, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseywatts/8bb0d7c76b7954f82d7c8ede409d6a6b to your computer and use it in GitHub Desktop.
Save caseywatts/8bb0d7c76b7954f82d7c8ede409d6a6b to your computer and use it in GitHub Desktop.
Stubbing Relationships in Model Unit Tests
UPDATE: Actually, doing this with `reopen` is apparently deprecated. Back to creating actual objects for relationships -_-
don't do this below stuff

Stubbing relationships in model unit tests

// model
export default DS.Model.extend({
  addonService: DS.belongsTo('addon-service')
});
// unit test setup that does NOT work
beforeEach(function () {
  addon = this.store().createRecord('addon', {
    addonService: Ember.Object.create({
      name: 'addon-service-name'
    })
  });
});
// unit test setup that works
beforeEach(function () {
  addon = this.store().createRecord('addon');
  addon.reopen({
    addonService: Ember.Object.create({
      name: 'addon-service-name'
    })
  });
});
@caseywatts
Copy link
Author

Actually, doing this with reopen is apparently deprecated.
Back to creating actual objects for relationships -_-

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