Skip to content

Commit

Permalink
add failing test for createRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickern committed Feb 3, 2024
1 parent 378e301 commit 576f118
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/unit/polymorphic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,47 @@ module('unit - Polymorphism', function (hooks) {
'fragment object was added to fragment array'
);
});

test('createRecord supports polymorphic typeKey for fragment and fragment arrays', async function (assert) {
const zoo = store.createRecord('zoo', {
star: {
$type: 'lion',
name: 'Mittens',
hasManes: true,
},
animals: [
{
$type: 'lion',
name: 'Alex',
hasManes: false,
},
{
$type: 'elephant',
name: 'Heffalump',
trunkLength: 7,
},
],
});

const star = zoo.star;
assert.ok(star instanceof Lion, 'star is a lion');
assert.strictEqual(star.name, 'Mittens', 'star name is correct');
assert.strictEqual(star.hasManes, true, 'star has manes');
assert.strictEqual(star.zoo, zoo, 'star fragment owner is correct');

const animals = zoo.animals;
assert.strictEqual(animals.length, 2);

const lion = animals.firstObject;
assert.ok(lion instanceof Lion, 'first animal is a lion');
assert.strictEqual(lion.name, 'Alex', 'lion name is correct');
assert.false(lion.hasManes, 'lion does not have manes');
assert.strictEqual(lion.zoo, zoo, 'lion fragment owner is correct');

const elephant = animals.lastObject;
assert.ok(elephant instanceof Elephant, 'second animal is an elephant');
assert.strictEqual(elephant.name, 'Heffalump', 'elephant name is correct');
assert.strictEqual(elephant.trunkLength, 7, 'trunk length is correct');
assert.strictEqual(elephant.zoo, zoo, 'elephant fragment owner is correct');
});
});

0 comments on commit 576f118

Please sign in to comment.