Skip to content

Commit a85ed87

Browse files
NullVoxPopuliclaude
andcommitted
Add tests for fn as MustacheStatement
Test fn in attribute position (e.g. <Child @callback={{fn greet "hello"}} />) to cover the MustacheStatement visitor path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6e9bad9 commit a85ed87

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/@glimmer-workspace/integration-tests/test/keywords/fn-runtime-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ class KeywordFn extends RenderTest {
5151
assert.verifySteps(['hello']);
5252
}
5353

54+
@test
55+
'MustacheStatement with explicit scope'(assert: Assert) {
56+
let greet = (greeting: string) => {
57+
assert.step(greeting);
58+
};
59+
60+
const Child = template('<button {{on "click" @callback}}>Click</button>', {
61+
strictMode: true,
62+
});
63+
64+
const compiled = template('<Child @callback={{fn greet "hello"}} />', {
65+
strictMode: true,
66+
scope: () => ({
67+
greet,
68+
Child,
69+
}),
70+
});
71+
72+
this.renderComponent(compiled);
73+
74+
castToBrowser(this.element, 'div').querySelector('button')!.click();
75+
assert.verifySteps(['hello']);
76+
}
77+
5478
@test
5579
'no eval and no scope'(assert: Assert) {
5680
class Foo extends GlimmerishComponent {

packages/@glimmer-workspace/integration-tests/test/keywords/fn-test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ class KeywordFn extends RenderTest {
5757
assert.verifySteps(['hello']);
5858
}
5959

60+
@test
61+
'it works as a MustacheStatement'(assert: Assert) {
62+
let greet = (greeting: string) => {
63+
assert.step(greeting);
64+
};
65+
66+
const Child = template('<button {{on "click" @callback}}>Click</button>', {
67+
strictMode: true,
68+
scope: () => ({ on }),
69+
});
70+
71+
const compiled = template('<Child @callback={{fn greet "hello"}} />', {
72+
strictMode: true,
73+
scope: () => ({
74+
greet,
75+
fn,
76+
Child,
77+
}),
78+
});
79+
80+
this.renderComponent(compiled);
81+
82+
castToBrowser(this.element, 'div').querySelector('button')!.click();
83+
assert.verifySteps(['hello']);
84+
}
85+
6086
@test
6187
'can be shadowed'(assert: Assert) {
6288
let fn = () => {

0 commit comments

Comments
 (0)