Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tests for #613 #725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions test-app/tests/integration/modifiers/functional-modifier-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,54 @@ module('Integration | Modifiers | functional modifier', function (hooks) {
assert.ok(teardownCalls.includes('A'));
assert.ok(teardownCalls.includes('B'));
});

test('teardown is invoked for a dynamically applied modifier', async function (this: Context, assert) {
const teardownCalls: string[] = [];

class State {
@tracked isRendered = true;
songbird = modifier(() => {
return () => teardownCalls.push('destroyed');
});
}

const state = (this.state = new State());

await render(hbs`
<h1 {{ (if this.state.isRendered this.state.songbird)}}>A</h1>
`);

state.isRendered = false;
await settled();

assert.strictEqual(teardownCalls.length, 1);
assert.ok(teardownCalls.includes('destroyed'));
});

test('teardown is invoked for a dynamically curried modifier', async function (this: Context, assert) {
const teardownCalls: string[] = [];

class State {
@tracked isRendered = true;
songbird = modifier((_, [val]: [string]) => {
return () => teardownCalls.push(val);
});
}

const state = (this.state = new State());

await render(hbs`
<h1 {{ (if this.state.isRendered (modifier this.state.songbird 'A'))}}>A</h1>
<h1 {{ (if this.state.isRendered (modifier this.state.songbird 'B'))}}>B</h1>
`);

state.isRendered = false;
await settled();

assert.strictEqual(teardownCalls.length, 2);
assert.ok(teardownCalls.includes('A'));
assert.ok(teardownCalls.includes('B'));
});
});

test('auto-tracking behavior', async function (this: Context, assert) {
Expand Down