diff --git a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts index 2a2dcd8de..c08c2a495 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts @@ -866,7 +866,7 @@ export class GlimmerishComponents extends RenderTest { @test({ kind: 'glimmer' }) 'destruction is not autotracked'() { class State { @tracked willDestroyCalls = 0; - increment = () => this.willDestroyCalls++; + incrementWillDestroy = () => this.willDestroyCalls++; } let state = new State(); class Child extends GlimmerishComponent { @@ -884,26 +884,62 @@ export class GlimmerishComponents extends RenderTest { this.registerComponent( 'Glimmer', 'Example', - ` -
willDestroyCalls: {{@willDestroyCalls}}
+ `willDestroyCalls: {{@willDestroyCalls}}
{{#if this.showChild}}willDestroyCalls: ${calls}
+ + a child +`; + } + return `willDestroyCalls: ${calls}
+ + +`; + }; + + const el = () => this.element as unknown as HTMLElement; + const click = () => { + el().querySelector('button')?.click(); + this.rerender(); + }; + + this.assert.strictEqual(state.willDestroyCalls, 0, '0 destructions'); + this.assertHTML(output(0, true), 'initial render'); + + click(); + this.assert.strictEqual(state.willDestroyCalls, 1, '1 destruction'); + this.assertHTML(output(1, false), 'destroyed once'); + + click(); + this.assert.strictEqual(state.willDestroyCalls, 1, '1 destruction'); + this.assertHTML(output(1, true), 'shown again, no change'); + + click(); + this.assert.strictEqual(state.willDestroyCalls, 2, '2 destruction'); + this.assertHTML(output(2, false), 'destroyed twice'); + + this.destroy(); this.assertHTML('', 'destroys correctly'); }