-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: A(PromiseManyArray) should have no-effect
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/-ember-data/tests/integration/relationships/promise-many-array-test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { A } from '@ember/array'; | ||
import { w } from '@ember/string'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import { setupRenderingTest } from 'ember-qunit'; | ||
|
||
import Model, { attr, hasMany } from '@ember-data/model'; | ||
|
||
module('PromiseManyArray side-affected by EmberArray', (hooks) => { | ||
setupRenderingTest(hooks); | ||
|
||
test('PromiseManyArray is not side-affected by EmberArray', async function (assert) { | ||
const { owner } = this; | ||
class Person extends Model { | ||
@attr('string') name; | ||
} | ||
class Group extends Model { | ||
@hasMany('person', { inverse: null }) members; | ||
} | ||
owner.register('model:person', Person); | ||
owner.register('model:group', Group); | ||
const store = owner.lookup('service:store'); | ||
const members = w('Bob John Michael Larry Lucy').map((name) => store.createRecord('person', { name })); | ||
const group = store.createRecord('group', { members }); | ||
|
||
const replaceFn = group.members.replace; | ||
assert.strictEqual(group.members.length, 5, 'initial length is correct'); | ||
|
||
group.members.replace(0, 1); | ||
assert.strictEqual(group.members.length, 4, 'updated length is correct'); | ||
|
||
A(group.members); | ||
|
||
assert.strictEqual(replaceFn, group.members.replace, 'we have the same function for replace'); | ||
group.members.replace(0, 1); | ||
assert.strictEqual(group.members.length, 3, 'updated length is correct'); | ||
}); | ||
}); |
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
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