-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathdid-update-test.js
More file actions
71 lines (55 loc) · 1.96 KB
/
did-update-test.js
File metadata and controls
71 lines (55 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, setupOnerror } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Integration | Modifier | did-update', function (hooks) {
setupRenderingTest(hooks);
test('it basically works', async function (assert) {
assert.expect(4);
this.someMethod = (element, positional, named) => {
assert.equal(element.tagName, 'DIV', 'correct element tagName');
assert.dom(element).hasAttribute('data-foo', 'some-thing');
assert.namedArgsEqual(named, {}, 'named args match');
assert.deepEqual(positional, ['update'], 'positional args match');
};
this.set('boundValue', 'initial');
await render(
hbs`<div data-foo="some-thing" {{did-update this.someMethod this.boundValue}}></div>`
);
this.set('boundValue', 'update');
});
test('provides a useful error on install', async function (assert) {
assert.expect(1);
// Setup error capturing
setupOnerror(function (err) {
assert.equal(
err.toString(),
`TypeError: did-update expected a function, instead received "undefined"`
);
});
await render(hbs`
<div {{did-update this.nonExistentMethod}}></div>
`);
// Reset error capturing
setupOnerror();
});
test('provides a useful error on update', async function (assert) {
assert.expect(1);
// Start with a valid function so that install works
this.set('nonExistentMethod', () => {});
// Setup error capturing
setupOnerror(function (err) {
assert.equal(
err.toString(),
`TypeError: did-update expected a function, instead received "undefined"`
);
});
await render(hbs`
<div {{did-update this.nonExistentMethod}}></div>
`);
// Remove the function to trigger an error on update
this.set('nonExistentMethod', undefined);
// Reset error capturing
setupOnerror();
});
});