Skip to content

Commit 71c57ce

Browse files
committed
Updated tests
1 parent c8eddbb commit 71c57ce

2 files changed

Lines changed: 49 additions & 53 deletions

File tree

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ class KeywordHashRuntime extends RenderTest {
2020
assert.step('captured');
2121
};
2222

23-
const compiled = template(
24-
'<button {{on "click" (fn capture (hash greeting="hello"))}}>Click</button>',
25-
{
26-
strictMode: true,
27-
scope: () => ({
28-
capture,
29-
}),
30-
}
31-
);
23+
const compiled = template('{{capture (hash greeting="hello" farewell="goodbye")}}', {
24+
strictMode: true,
25+
scope: () => ({
26+
capture,
27+
}),
28+
});
3229

3330
this.renderComponent(compiled);
3431

35-
castToBrowser(this.element, 'div').querySelector('button')!.click();
3632
assert.verifySteps(['captured']);
3733
assert.strictEqual(receivedData?.['greeting'], 'hello');
34+
assert.strictEqual(receivedData?.['farewell'], 'goodbye');
3835
}
3936

4037
@test
@@ -48,19 +45,15 @@ class KeywordHashRuntime extends RenderTest {
4845

4946
hide(capture);
5047

51-
const compiled = template(
52-
'<button {{on "click" (fn capture (hash greeting="hello"))}}>Click</button>',
53-
{
54-
strictMode: true,
55-
eval() {
56-
return eval(arguments[0]);
57-
},
58-
}
59-
);
48+
const compiled = template('{{capture (hash greeting="hello")}}', {
49+
strictMode: true,
50+
eval() {
51+
return eval(arguments[0]);
52+
},
53+
});
6054

6155
this.renderComponent(compiled);
6256

63-
castToBrowser(this.element, 'div').querySelector('button')!.click();
6457
assert.verifySteps(['captured']);
6558
assert.strictEqual(receivedData?.['greeting'], 'hello');
6659
}
@@ -96,7 +89,7 @@ class KeywordHashRuntime extends RenderTest {
9689
assert.step('captured');
9790
};
9891

99-
const Child = template('<button {{on "click" (fn capture @data)}}>Click</button>', {
92+
const Child = template('{{capture @data}}', {
10093
strictMode: true,
10194
scope: () => ({ capture }),
10295
});
@@ -110,7 +103,6 @@ class KeywordHashRuntime extends RenderTest {
110103

111104
this.renderComponent(compiled);
112105

113-
castToBrowser(this.element, 'div').querySelector('button')!.click();
114106
assert.verifySteps(['captured']);
115107
assert.strictEqual(receivedData?.['greeting'], 'hello');
116108
}

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { castToBrowser } from '@glimmer/debug-util';
21
import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
32

43
import { template } from '@ember/template-compiler';
5-
import { fn, hash } from '@ember/helper';
6-
import { on } from '@ember/modifier';
74

85
class KeywordHash extends RenderTest {
96
static suiteName = 'keyword helper: hash';
@@ -17,29 +14,42 @@ class KeywordHash extends RenderTest {
1714
assert.step('captured');
1815
};
1916

20-
const compiled = template(
21-
'<button {{on "click" (fn capture (hash greeting="hello" farewell="goodbye"))}}>Click</button>',
22-
{
23-
strictMode: true,
24-
scope: () => ({
25-
capture,
26-
fn,
27-
hash,
28-
on,
29-
}),
30-
}
31-
);
17+
const compiled = template('{{capture (hash greeting="hello" farewell="goodbye")}}', {
18+
strictMode: true,
19+
scope: () => ({
20+
capture,
21+
}),
22+
});
3223

3324
this.renderComponent(compiled);
3425

35-
castToBrowser(this.element, 'div').querySelector('button')!.click();
3626
assert.verifySteps(['captured']);
3727
assert.strictEqual(receivedData?.['greeting'], 'hello');
3828
assert.strictEqual(receivedData?.['farewell'], 'goodbye');
3929
}
4030

4131
@test
42-
'it works with the runtime compiler'(assert: Assert) {
32+
'it can be shadowed'(assert: Assert) {
33+
let receivedData: string | undefined;
34+
35+
let hash = (data: string) => {
36+
receivedData = data;
37+
};
38+
39+
hide(hash);
40+
41+
const compiled = template('{{hash "hello"}}', {
42+
strictMode: true,
43+
scope: () => ({ hash }),
44+
});
45+
46+
this.renderComponent(compiled);
47+
48+
assert.strictEqual(receivedData, 'hello');
49+
}
50+
51+
@test
52+
'it works with implicit scope form'(assert: Assert) {
4353
let receivedData: Record<string, unknown> | undefined;
4454

4555
let capture = (data: Record<string, unknown>) => {
@@ -49,19 +59,15 @@ class KeywordHash extends RenderTest {
4959

5060
hide(capture);
5161

52-
const compiled = template(
53-
'<button {{on "click" (fn capture (hash greeting="hello"))}}>Click</button>',
54-
{
55-
strictMode: true,
56-
eval() {
57-
return eval(arguments[0]);
58-
},
59-
}
60-
);
62+
const compiled = template('{{capture (hash greeting="hello")}}', {
63+
strictMode: true,
64+
eval() {
65+
return eval(arguments[0]);
66+
},
67+
});
6168

6269
this.renderComponent(compiled);
6370

64-
castToBrowser(this.element, 'div').querySelector('button')!.click();
6571
assert.verifySteps(['captured']);
6672
assert.strictEqual(receivedData?.['greeting'], 'hello');
6773
}
@@ -75,22 +81,20 @@ class KeywordHash extends RenderTest {
7581
assert.step('captured');
7682
};
7783

78-
const Child = template('<button {{on "click" (fn capture @data)}}>Click</button>', {
84+
const Child = template('{{capture @data}}', {
7985
strictMode: true,
80-
scope: () => ({ on, fn, capture }),
86+
scope: () => ({ capture }),
8187
});
8288

8389
const compiled = template('<Child @data={{hash greeting="hello"}} />', {
8490
strictMode: true,
8591
scope: () => ({
86-
hash,
8792
Child,
8893
}),
8994
});
9095

9196
this.renderComponent(compiled);
9297

93-
castToBrowser(this.element, 'div').querySelector('button')!.click();
9498
assert.verifySteps(['captured']);
9599
assert.strictEqual(receivedData?.['greeting'], 'hello');
96100
}

0 commit comments

Comments
 (0)