-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa56b35
commit 71d75a9
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ test('Basic usage', function(assert) { | |
this.set('isAdmin', false); | ||
|
||
this.render(hbs`{{x-changer email=email isAdmin=isAdmin name=name}}`); | ||
|
||
assert.equal(didChangeAttrsCallCount, 0, '`didChangeAttrs` is not called on initial render'); | ||
|
||
this.set('email', '[email protected]'); | ||
|
@@ -47,3 +48,63 @@ test('Basic usage', function(assert) { | |
this.set('name', 'TheTomster'); | ||
assert.equal(didChangeAttrsCallCount, 1, '`didChangeAttrs` is not called when an untracked attribute is changed'); | ||
}); | ||
|
||
test('Custom isEqual', function(assert) { | ||
let changedAttrs, didChangeAttrsCallCount = 0; | ||
|
||
registerComponent(this, { | ||
didChangeAttrsConfig: { | ||
attrs: ['user', 'isAdmin'], | ||
isEqual(key, a, b) { | ||
if (key === 'user') { | ||
return (a && b) ? a.id === b.id : a === b; | ||
} | ||
return a === b; | ||
} | ||
}, | ||
|
||
didChangeAttrs(changes) { | ||
this._super(...arguments); | ||
|
||
didChangeAttrsCallCount++; | ||
changedAttrs = changes; | ||
} | ||
}); | ||
|
||
this.set('user', { name: 'Tomster', id: '123' }); | ||
this.set('isAdmin', false); | ||
|
||
this.render(hbs`{{x-changer user=user isAdmin=isAdmin}}`); | ||
|
||
assert.equal(didChangeAttrsCallCount, 0, '`didChangeAttrs` is not called on initial render'); | ||
|
||
this.set('user', { name: 'TheTomster', id: '123' }); | ||
|
||
assert.equal(didChangeAttrsCallCount, 0, '`didChangeAttrs` is not called because user entities are equal'); | ||
|
||
this.set('user', { name: 'Zoey', id: '456' }); | ||
|
||
assert.equal(didChangeAttrsCallCount, 1, '`didChangeAttrs` is called because user entities are not equal'); | ||
assert.deepEqual(changedAttrs, { | ||
user: { | ||
previous: { | ||
id: '123', | ||
name: 'Tomster' | ||
}, | ||
current: { | ||
id: '456', | ||
name: 'Zoey' | ||
} | ||
} | ||
}, '`user` included in `changedAttrs` because `user.id` is different'); | ||
|
||
this.set('isAdmin', true); | ||
|
||
assert.equal(didChangeAttrsCallCount, 2, '`didChangeAttrs` is called because isAdmin changed'); | ||
assert.deepEqual(changedAttrs, { | ||
isAdmin: { | ||
previous: false, | ||
current: true | ||
} | ||
}, '`isAdmin` included in `changedAttrs` because it changed'); | ||
}); |