diff --git a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts index 3c6426e1d..2a2dcd8de 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/suites/components.ts @@ -864,41 +864,45 @@ export class GlimmerishComponents extends RenderTest { } @test({ kind: 'glimmer' }) 'destruction is not autotracked'() { - let fooCount = 0; - class Foo extends GlimmerishComponent { - declare args: { exclaim: string }; - - constructor(owner: Owner, args: Dict) { - super(owner, args); - } - - @tracked hello = 'hello'; - - get foo() { - fooCount++; - return this.hello + this.args.exclaim; + class State { + @tracked willDestroyCalls = 0; + increment = () => this.willDestroyCalls++; + } + let state = new State(); + class Child extends GlimmerishComponent { + declare args: { incrementWillDestroy: () => void }; + override willDestroy() { + super.willDestroy(); + this.args.incrementWillDestroy(); } } - this.registerComponent('Glimmer', 'Foo', '{{this.foo}}', Foo); - - this.render('{{#if this.showing}}{{/if}}', { - showing: false, - exclaim: '?', - }); - - this.assert.strictEqual(fooCount, 0); - - this.rerender({ showing: true }); - this.assert.strictEqual(fooCount, 1); + class Example extends GlimmerishComponent { + @tracked showChild = true; + toggleChild = () => (this.showChild = !this.showChild); + } + this.registerComponent('Glimmer', 'Child', 'a child', Child); + this.registerComponent( + 'Glimmer', + 'Example', + ` +

willDestroyCalls: {{@willDestroyCalls}}

+ - this.rerender({ exclaim: '!' }); - this.assert.strictEqual(fooCount, 2); + {{#if this.showChild}} + + {{/if}} + `, + Example + ); - this.rerender({ showing: false, exclaim: '!!!' }); - this.assert.strictEqual(fooCount, 2); + this.render( + '', + { state } + ); - this.destroy(); - this.assert.strictEqual(fooCount, 2); + this.assert.strictEqual(this.takeSnapshot(), '..'); + this.assert.strictEqual(state.willDestroyCalls, 0); + this.assertHTML('', 'p', 'destroys correctly'); this.assertHTML('', 'destroys correctly'); }