Skip to content

Commit

Permalink
Getting there?
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Nov 13, 2024
1 parent ebd45a3 commit 31d208f
Showing 1 changed file with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}<Foo @exclaim={{this.exclaim}} />{{/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',
`
<p>willDestroyCalls: {{@willDestroyCalls}}</p>
<button {{on "click" this.toggleChild}}>Toggle child</button>
this.rerender({ exclaim: '!' });
this.assert.strictEqual(fooCount, 2);
{{#if this.showChild}}
<Child @incrementWillDestroy={{@incrementWillDestroy}} />
{{/if}}
`,
Example
);

this.rerender({ showing: false, exclaim: '!!!' });
this.assert.strictEqual(fooCount, 2);
this.render(
'<Example @incrementWillDestroy={{this.state.increment}} @willDestroyCalls={{this.state.willDestroyCalls}} />',
{ 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');
}
Expand Down

0 comments on commit 31d208f

Please sign in to comment.