Skip to content

Commit 7f992bd

Browse files
committed
Simplify tests
1 parent 09afb95 commit 7f992bd

2 files changed

Lines changed: 44 additions & 139 deletions

File tree

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

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,56 @@ class KeywordArrayRuntime extends RenderTest {
1212
static suiteName = 'keyword helper: array (runtime)';
1313

1414
@test
15-
'explicit scope'(assert: Assert) {
16-
let receivedData: unknown[] | undefined;
17-
18-
let capture = (data: unknown[]) => {
19-
receivedData = data;
20-
assert.step('captured');
21-
};
22-
23-
const compiled = template(
24-
'<button {{on "click" (fn capture (array "hello" "goodbye"))}}>Click</button>',
25-
{
26-
strictMode: true,
27-
scope: () => ({
28-
capture,
29-
}),
30-
}
31-
);
15+
'it works'() {
16+
const compiled = template('{{JSON.stringify (array "hello" "goodbye")}}', {
17+
strictMode: true,
18+
scope: () => ({ JSON }),
19+
});
3220

3321
this.renderComponent(compiled);
34-
35-
castToBrowser(this.element, 'div').querySelector('button')!.click();
36-
assert.verifySteps(['captured']);
37-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
22+
this.assertHTML('["hello","goodbye"]');
3823
}
3924

4025
@test
41-
'implicit scope'(assert: Assert) {
42-
let receivedData: unknown[] | undefined;
43-
44-
let capture = (data: unknown[]) => {
45-
receivedData = data;
46-
assert.step('captured');
47-
};
26+
'it works (shadowed)'() {
27+
const array = (x: string) => x.toUpperCase();
28+
const compiled = template('{{array "hello"}}', {
29+
strictMode: true,
30+
scope: () => ({ JSON, array }),
31+
});
4832

49-
hide(capture);
33+
this.renderComponent(compiled);
34+
this.assertHTML('HELLO');
35+
}
5036

51-
const compiled = template(
52-
'<button {{on "click" (fn capture (array "hello" "goodbye"))}}>Click</button>',
53-
{
54-
strictMode: true,
55-
eval() {
56-
return eval(arguments[0]);
57-
},
58-
}
59-
);
37+
@test
38+
'implicit scope'() {
39+
const compiled = template('{{JSON.stringify (array "hello" "goodbye")}}', {
40+
strictMode: true,
41+
eval() {
42+
return eval(arguments[0]);
43+
},
44+
});
6045

6146
this.renderComponent(compiled);
62-
63-
castToBrowser(this.element, 'div').querySelector('button')!.click();
64-
assert.verifySteps(['captured']);
65-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
47+
this.assertHTML('["hello","goodbye"]');
6648
}
6749

6850
@test
69-
'MustacheStatement with explicit scope'(assert: Assert) {
70-
let receivedData: unknown[] | undefined;
51+
'implicit scope (shadowed)'() {
52+
const array = (...data: string[]) => data.reverse();
7153

72-
let capture = (data: unknown[]) => {
73-
receivedData = data;
74-
assert.step('captured');
75-
};
54+
hide(array);
7655

77-
const Child = template('<button {{on "click" (fn capture @items)}}>Click</button>', {
56+
const compiled = template('{{JSON.stringify (array "hello" "goodbye")}}', {
7857
strictMode: true,
79-
scope: () => ({ capture }),
80-
});
81-
82-
const compiled = template('<Child @items={{array "hello" "goodbye"}} />', {
83-
strictMode: true,
84-
scope: () => ({
85-
Child,
86-
}),
58+
eval() {
59+
return eval(arguments[0]);
60+
},
8761
});
8862

8963
this.renderComponent(compiled);
90-
91-
castToBrowser(this.element, 'div').querySelector('button')!.click();
92-
assert.verifySteps(['captured']);
93-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
64+
this.assertHTML('["goodbye","hello"]');
9465
}
9566

9667
@test

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

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

4-
import { template } from '@ember/template-compiler/runtime';
5-
import { array, fn } from '@ember/helper';
6-
import { on } from '@ember/modifier';
3+
import { template } from '@ember/template-compiler';
74

85
class KeywordArray extends RenderTest {
96
static suiteName = 'keyword helper: array';
107

118
@test
12-
'it works'(assert: Assert) {
13-
let receivedData: unknown[] | undefined;
14-
15-
let capture = (data: unknown[]) => {
16-
receivedData = data;
17-
assert.step('captured');
18-
};
19-
20-
const compiled = template(
21-
'<button {{on "click" (fn capture (array "hello" "goodbye"))}}>Click</button>',
22-
{
23-
strictMode: true,
24-
scope: () => ({
25-
capture,
26-
fn,
27-
array,
28-
on,
29-
}),
30-
}
31-
);
32-
33-
this.renderComponent(compiled);
34-
35-
castToBrowser(this.element, 'div').querySelector('button')!.click();
36-
assert.verifySteps(['captured']);
37-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
38-
}
39-
40-
@test
41-
'it works with the runtime compiler'(assert: Assert) {
42-
let receivedData: unknown[] | undefined;
43-
44-
let capture = (data: unknown[]) => {
45-
receivedData = data;
46-
assert.step('captured');
47-
};
48-
49-
hide(capture);
50-
51-
const compiled = template(
52-
'<button {{on "click" (fn capture (array "hello" "goodbye"))}}>Click</button>',
53-
{
54-
strictMode: true,
55-
eval() {
56-
return eval(arguments[0]);
57-
},
58-
}
59-
);
9+
'it works'() {
10+
const compiled = template('{{JSON.stringify (array "hello" "goodbye")}}', {
11+
strictMode: true,
12+
scope: () => ({ JSON }),
13+
});
6014

6115
this.renderComponent(compiled);
62-
63-
castToBrowser(this.element, 'div').querySelector('button')!.click();
64-
assert.verifySteps(['captured']);
65-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
16+
this.assertHTML('["hello","goodbye"]');
6617
}
6718

6819
@test
69-
'it works as a MustacheStatement'(assert: Assert) {
70-
let receivedData: unknown[] | undefined;
71-
72-
let capture = (data: unknown[]) => {
73-
receivedData = data;
74-
assert.step('captured');
75-
};
76-
77-
const Child = template('<button {{on "click" (fn capture @items)}}>Click</button>', {
20+
'it works (shadowed)'() {
21+
const array = (x: string) => x.toUpperCase();
22+
const compiled = template('{{array "hello"}}', {
7823
strictMode: true,
79-
scope: () => ({ on, fn, capture }),
80-
});
81-
82-
const compiled = template('<Child @items={{array "hello" "goodbye"}} />', {
83-
strictMode: true,
84-
scope: () => ({
85-
array,
86-
Child,
87-
}),
24+
scope: () => ({ JSON, array }),
8825
});
8926

9027
this.renderComponent(compiled);
91-
92-
castToBrowser(this.element, 'div').querySelector('button')!.click();
93-
assert.verifySteps(['captured']);
94-
assert.deepEqual(receivedData, ['hello', 'goodbye']);
28+
this.assertHTML('HELLO');
9529
}
9630
}
9731

0 commit comments

Comments
 (0)