Skip to content

Commit

Permalink
[BUGFIX model] assertions around create need to account for Ember's own
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 4, 2019
1 parent 081432c commit 1df8333
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ module('unit/model - Model', function(hooks) {
async function(assert) {
class NativePerson extends Model {}
const LegacyPerson = Model.extend({});
const EmberObjectNewError = 'was not instantiated correctly.';
assert.throws(
() => {
Expand All @@ -741,7 +742,16 @@ module('unit/model - Model', function(hooks) {
assert.throws(
() => {
new NativePerson();
try {
// the `{}` here is so that in recent ember we throw a nice error vs an
// obtuse error. An error will thrown in any case though.
new NativePerson({});
} catch (e) {
if (e.message.indexOf(EmberObjectNewError) !== -1) {
throw new Error('You should not call `create` on a model');
}
throw e;
}
},
/You should not call `create` on a model/,
'Throws an error when calling instantiating via new Model'
Expand All @@ -757,7 +767,16 @@ module('unit/model - Model', function(hooks) {
assert.throws(
() => {
new LegacyPerson();
try {
// the `{}` here is so that in recent ember we throw a nice error vs an
// obtuse error. An error will thrown in any case though.
new LegacyPerson({});
} catch (e) {
if (e.message.indexOf(EmberObjectNewError) !== -1) {
throw new Error('You should not call `create` on a model');
}
throw e;
}
},
/You should not call `create` on a model/,
'Throws an error when calling instantiating view new Model()'
Expand Down

0 comments on commit 1df8333

Please sign in to comment.