Skip to content

Commit dd39f78

Browse files
committed
Cleanup
1 parent 996d28e commit dd39f78

3 files changed

Lines changed: 47 additions & 59 deletions

File tree

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import { template } from '@ember/template-compiler/runtime';
1010

11-
class KeywordElement extends RenderTest {
11+
class KeywordElementRuntime extends RenderTest {
1212
static suiteName = 'keyword helper: element (runtime)';
1313

1414
@test
@@ -26,40 +26,30 @@ class KeywordElement extends RenderTest {
2626
}
2727

2828
@test
29-
'implicit scope'(assert: Assert) {
30-
const compiled = template('{{#let (element "h1") as |Tag|}}<Tag>Hello</Tag>{{/let}}', {
29+
'explicit scope (shadowed)'() {
30+
const compiled = template('{{element "h1"}}', {
3131
strictMode: true,
32-
eval() {
33-
return eval(arguments[0]);
34-
},
32+
scope: () => ({ element: () => 'surprise' }),
3533
});
3634

3735
this.renderComponent(compiled);
38-
39-
let h1 = castToBrowser(this.element, 'div').querySelector('h1');
40-
assert.ok(h1, 'h1 element exists');
41-
assert.strictEqual(h1!.textContent, 'Hello');
36+
this.assertHTML('surprise');
4237
}
4338

4439
@test
45-
'MustacheStatement with explicit scope'(assert: Assert) {
46-
const Child = template('{{#let @tag as |Tag|}}<Tag>World</Tag>{{/let}}', {
47-
strictMode: true,
48-
scope: () => ({}),
49-
});
50-
51-
const compiled = template('<Child @tag={{element "span"}} />', {
40+
'implicit scope (eval)'(assert: Assert) {
41+
const compiled = template('{{#let (element "h1") as |Tag|}}<Tag>Hello</Tag>{{/let}}', {
5242
strictMode: true,
53-
scope: () => ({
54-
Child,
55-
}),
43+
eval() {
44+
return eval(arguments[0]);
45+
},
5646
});
5747

5848
this.renderComponent(compiled);
5949

60-
let span = castToBrowser(this.element, 'div').querySelector('span');
61-
assert.ok(span, 'span element exists');
62-
assert.strictEqual(span!.textContent, 'World');
50+
let h1 = castToBrowser(this.element, 'div').querySelector('h1');
51+
assert.ok(h1, 'h1 element exists');
52+
assert.strictEqual(h1!.textContent, 'Hello');
6353
}
6454

6555
@test
@@ -81,4 +71,4 @@ class KeywordElement extends RenderTest {
8171
}
8272
}
8373

84-
jitSuite(KeywordElement);
74+
jitSuite(KeywordElementRuntime);

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import { castToBrowser } from '@glimmer/debug-util';
22
import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
33

44
import { template } from '@ember/template-compiler';
5-
import { element } from '@ember/helper';
65

76
class KeywordElement extends RenderTest {
87
static suiteName = 'keyword helper: element';
98

109
@test
11-
'it works as a SubExpression'(assert: Assert) {
10+
'explicit scope'(assert: Assert) {
1211
const compiled = template('{{#let (element "h1") as |Tag|}}<Tag>Hello</Tag>{{/let}}', {
1312
strictMode: true,
14-
scope: () => ({ element }),
13+
scope: () => ({}),
1514
});
1615

1716
this.renderComponent(compiled);
@@ -22,9 +21,19 @@ class KeywordElement extends RenderTest {
2221
}
2322

2423
@test
25-
'it works with the runtime compiler'(assert: Assert) {
26-
hide(element);
24+
'explicit scope (shadowed)'() {
25+
let element = () => 'surprise';
26+
const compiled = template('{{element "h1"}}', {
27+
strictMode: true,
28+
scope: () => ({ element }),
29+
});
2730

31+
this.renderComponent(compiled);
32+
this.assertHTML('surprise');
33+
}
34+
35+
@test
36+
'implicit scope (eval)'(assert: Assert) {
2837
const compiled = template('{{#let (element "h1") as |Tag|}}<Tag>Hello</Tag>{{/let}}', {
2938
strictMode: true,
3039
eval() {
@@ -40,18 +49,15 @@ class KeywordElement extends RenderTest {
4049
}
4150

4251
@test
43-
'it works as a MustacheStatement'(assert: Assert) {
52+
'MustacheStatement'(assert: Assert) {
4453
const Child = template('{{#let @tag as |Tag|}}<Tag>World</Tag>{{/let}}', {
4554
strictMode: true,
4655
scope: () => ({}),
4756
});
4857

4958
const compiled = template('<Child @tag={{element "span"}} />', {
5059
strictMode: true,
51-
scope: () => ({
52-
element,
53-
Child,
54-
}),
60+
scope: () => ({ Child }),
5561
});
5662

5763
this.renderComponent(compiled);
@@ -63,17 +69,3 @@ class KeywordElement extends RenderTest {
6369
}
6470

6571
jitSuite(KeywordElement);
66-
67-
/**
68-
* This function is used to hide a variable from the transpiler, so that it
69-
* doesn't get removed as "unused". It does not actually do anything with the
70-
* variable, it just makes it be part of an expression that the transpiler
71-
* won't remove.
72-
*
73-
* It's a bit of a hack, but it's necessary for testing.
74-
*
75-
* @param variable The variable to hide.
76-
*/
77-
const hide = (variable: unknown) => {
78-
new Function(`return (${JSON.stringify(variable)});`);
79-
};

smoke-tests/scenarios/basic-test.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,29 @@ function basicTest(scenarios: Scenarios, appName: string) {
406406
import { setupRenderingTest } from 'ember-qunit';
407407
import { render } from '@ember/test-helpers';
408408
409-
import Component from '@glimmer/component';
410-
411-
class Demo extends Component {
412-
<template>
413-
{{#let (element "h1") as |Tag|}}
414-
<Tag class="greeting">Hello from element keyword</Tag>
415-
{{/let}}
416-
</template>
417-
}
418-
419409
module('{{element}} as keyword', function(hooks) {
420410
setupRenderingTest(hooks);
421411
422412
test('it works', async function(assert) {
423-
await render(Demo);
413+
await render(
414+
<template>
415+
{{#let (element "h1") as |Tag|}}
416+
<Tag class="greeting">Hello from element keyword</Tag>
417+
{{/let}}
418+
</template>
419+
);
424420
assert.dom('h1.greeting').hasText('Hello from element keyword');
425421
});
422+
423+
test('can be shadowed', async function(assert) {
424+
let element = () => 'surprise';
425+
await render(
426+
<template>
427+
<span data-test>{{element "h1"}}</span>
428+
</template>
429+
);
430+
assert.dom('[data-test]').hasText('surprise');
431+
});
426432
});
427433
`,
428434
'fn-as-keyword-but-its-shadowed-test.gjs': `

0 commit comments

Comments
 (0)