Skip to content

Commit 2cda1f4

Browse files
committed
Changes after being told to run tests
1 parent 243e40d commit 2cda1f4

File tree

2 files changed

+72
-82
lines changed

2 files changed

+72
-82
lines changed

packages/@glimmer-workspace/integration-tests/test/helpers/if-inline-test.ts

+64-79
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
GlimmerishComponent,
2+
defineComponent,
33
jitSuite,
44
RenderTest,
55
strip,
@@ -14,18 +14,15 @@ class IfInlineTest extends RenderTest {
1414
'inline if helper updates when tracked property changes'() {
1515
class Person {
1616
@tracked isActive = false;
17-
17+
1818
toggle() {
1919
this.isActive = !this.isActive;
2020
}
2121
}
2222

2323
const person = new Person();
2424

25-
this.render(
26-
strip`<div>{{if this.person.isActive "Active" "Inactive"}}</div>`,
27-
{ person }
28-
);
25+
this.render(strip`<div>{{if this.person.isActive "Active" "Inactive"}}</div>`, { person });
2926

3027
this.assertHTML('<div>Inactive</div>', 'Initial render shows inactive state');
3128
this.assertStableRerender();
@@ -43,18 +40,15 @@ class IfInlineTest extends RenderTest {
4340
'inline if helper with only truthy value updates when tracked property changes'() {
4441
class Person {
4542
@tracked isActive = false;
46-
43+
4744
toggle() {
4845
this.isActive = !this.isActive;
4946
}
5047
}
5148

5249
const person = new Person();
5350

54-
this.render(
55-
strip`<div>{{if this.person.isActive "Active"}}</div>`,
56-
{ person }
57-
);
51+
this.render(strip`<div>{{if this.person.isActive "Active"}}</div>`, { person });
5852

5953
this.assertHTML('<div></div>', 'Initial render shows empty when false');
6054
this.assertStableRerender();
@@ -70,142 +64,133 @@ class IfInlineTest extends RenderTest {
7064

7165
@test
7266
'inline if helper updates when component argument changes'() {
73-
let testComponent: TestComponent;
74-
75-
class TestComponent extends GlimmerishComponent {
76-
@tracked isActive = false;
77-
78-
constructor(owner: object, args: Record<string, unknown>) {
79-
super(owner, args);
80-
testComponent = this;
81-
}
82-
}
67+
const TestComponent = defineComponent({}, '{{if @isActive "Active" "Inactive"}}');
8368

84-
this.registerComponent(
85-
'Glimmer',
86-
'TestComponent',
87-
'{{if @isActive "Active" "Inactive"}}',
88-
TestComponent
89-
);
90-
91-
this.render(
92-
strip`<TestComponent @isActive={{this.isActive}} />`,
93-
{ isActive: false }
94-
);
69+
this.render('<TestComponent @isActive={{this.isActive}} />', {
70+
isActive: false,
71+
TestComponent,
72+
});
9573

9674
this.assertHTML('Inactive', 'Initial render shows inactive state');
9775
this.assertStableRerender();
9876

99-
this.rerender({ isActive: true });
77+
this.rerender({ isActive: true, TestComponent });
10078
this.assertHTML('Active', 'Updates when argument changes to true');
10179

102-
this.rerender({ isActive: false });
80+
this.rerender({ isActive: false, TestComponent });
10381
this.assertHTML('Inactive', 'Updates when argument changes to false');
10482
}
10583

10684
@test
10785
'inline if helper with components updates when tracked property changes'() {
10886
class Person {
10987
@tracked isActive = false;
110-
88+
11189
toggle() {
11290
this.isActive = !this.isActive;
11391
}
11492
}
11593

11694
const person = new Person();
11795

118-
class OkComponent extends GlimmerishComponent {}
119-
class KoComponent extends GlimmerishComponent {}
96+
const Ok = defineComponent({}, '<div>OK Component</div>');
97+
const Ko = defineComponent({}, '<div>KO Component</div>');
12098

121-
this.registerComponent('Glimmer', 'Ok', '<div>OK Component</div>', OkComponent);
122-
this.registerComponent('Glimmer', 'Ko', '<div>KO Component</div>', KoComponent);
99+
// Create a component with Ok and Ko in scope
100+
const TestContainer = defineComponent({ Ok, Ko }, '<div>{{if @isActive Ok Ko}}</div>');
123101

124-
this.render(
125-
strip`<div>{{if this.person.isActive Ok Ko}}</div>`,
126-
{ person }
127-
);
102+
this.render('<TestContainer @isActive={{this.person.isActive}} />', { person, TestContainer });
128103

129104
this.assertHTML('<div><div>KO Component</div></div>', 'Initial render shows KO component');
130105
this.assertStableRerender();
131106

132107
person.toggle();
133108
this.rerender();
134-
this.assertHTML('<div><div>OK Component</div></div>', 'Updates to OK component when tracked property changes to true');
109+
this.assertHTML(
110+
'<div><div>OK Component</div></div>',
111+
'Updates to OK component when tracked property changes to true'
112+
);
135113

136114
person.toggle();
137115
this.rerender();
138-
this.assertHTML('<div><div>KO Component</div></div>', 'Updates to KO component when tracked property changes to false');
116+
this.assertHTML(
117+
'<div><div>KO Component</div></div>',
118+
'Updates to KO component when tracked property changes to false'
119+
);
139120
}
140121

141122
@test
142123
'inline if helper with components updates when component argument changes'() {
143-
class OkComponent extends GlimmerishComponent {}
144-
class KoComponent extends GlimmerishComponent {}
145-
146-
this.registerComponent('Glimmer', 'Ok', '<div>OK Component</div>', OkComponent);
147-
this.registerComponent('Glimmer', 'Ko', '<div>KO Component</div>', KoComponent);
124+
const Ok = defineComponent({}, '<div>OK Component</div>');
125+
const Ko = defineComponent({}, '<div>KO Component</div>');
148126

149-
this.registerComponent(
150-
'Glimmer',
151-
'TestComponent',
152-
'{{if @isOk Ok Ko}}',
153-
class extends GlimmerishComponent {}
154-
);
127+
const TestComponent = defineComponent({ Ok, Ko }, '{{if @isOk Ok Ko}}');
155128

156-
this.render(
157-
strip`<TestComponent @isOk={{this.isOk}} />`,
158-
{ isOk: false }
159-
);
129+
this.render('<TestComponent @isOk={{this.isOk}} />', { isOk: false, TestComponent });
160130

161131
this.assertHTML('<div>KO Component</div>', 'Initial render shows KO component');
162132
this.assertStableRerender();
163133

164-
this.rerender({ isOk: true });
165-
this.assertHTML('<div>OK Component</div>', 'Updates to OK component when argument changes to true');
134+
this.rerender({ isOk: true, TestComponent });
135+
this.assertHTML(
136+
'<div>OK Component</div>',
137+
'Updates to OK component when argument changes to true'
138+
);
166139

167-
this.rerender({ isOk: false });
168-
this.assertHTML('<div>KO Component</div>', 'Updates to KO component when argument changes to false');
140+
this.rerender({ isOk: false, TestComponent });
141+
this.assertHTML(
142+
'<div>KO Component</div>',
143+
'Updates to KO component when argument changes to false'
144+
);
169145
}
170146

171147
@test
172148
'comparison with block form if helper using components'() {
173149
class Person {
174150
@tracked isActive = false;
175-
151+
176152
toggle() {
177153
this.isActive = !this.isActive;
178154
}
179155
}
180156

181157
const person = new Person();
182158

183-
class OkComponent extends GlimmerishComponent {}
184-
class KoComponent extends GlimmerishComponent {}
185-
186-
this.registerComponent('Glimmer', 'Ok', '<div>OK Component</div>', OkComponent);
187-
this.registerComponent('Glimmer', 'Ko', '<div>KO Component</div>', KoComponent);
159+
const Ok = defineComponent({}, '<div>OK Component</div>');
160+
const Ko = defineComponent({}, '<div>KO Component</div>');
188161

189-
this.render(
190-
strip`
162+
// Create a component with Ok and Ko in scope for both inline and block forms
163+
const TestContainer = defineComponent(
164+
{ Ok, Ko },
165+
`
191166
<div>
192-
Inline: {{if this.person.isActive Ok Ko}}
193-
Block: {{#if this.person.isActive}}<Ok />{{else}}<Ko />{{/if}}
167+
Inline: {{if @isActive Ok Ko}}
168+
Block: {{#if @isActive}}<Ok />{{else}}<Ko />{{/if}}
194169
</div>
195-
`,
196-
{ person }
170+
`
197171
);
198172

199-
this.assertHTML('<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>', 'Initial render both show KO component');
173+
this.render('<TestContainer @isActive={{this.person.isActive}} />', { person, TestContainer });
174+
175+
this.assertHTML(
176+
'<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>',
177+
'Initial render both show KO component'
178+
);
200179
this.assertStableRerender();
201180

202181
person.toggle();
203182
this.rerender();
204-
this.assertHTML('<div>Inline: <div>OK Component</div> Block: <div>OK Component</div></div>', 'Both update to OK component when tracked property changes to true');
183+
this.assertHTML(
184+
'<div>Inline: <div>OK Component</div> Block: <div>OK Component</div></div>',
185+
'Both update to OK component when tracked property changes to true'
186+
);
205187

206188
person.toggle();
207189
this.rerender();
208-
this.assertHTML('<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>', 'Both update to KO component when tracked property changes to false');
190+
this.assertHTML(
191+
'<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>',
192+
'Both update to KO component when tracked property changes to false'
193+
);
209194
}
210195
}
211196

packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,16 @@ APPEND_OPCODES.add(VM_IF_INLINE_OP, (vm) => {
287287
createComputeRef(() => {
288288
// Explicitly consume the condition reference to ensure tracking
289289
let conditionValue = valueForRef(condition);
290-
290+
291+
// Also explicitly consume truthy and falsy references to ensure proper tracking
292+
// when they are component references
293+
let truthyValue = valueForRef(truthy);
294+
let falsyValue = valueForRef(falsy);
295+
291296
if (toBool(conditionValue)) {
292-
return valueForRef(truthy);
297+
return truthyValue;
293298
} else {
294-
return valueForRef(falsy);
299+
return falsyValue;
295300
}
296301
})
297302
);

0 commit comments

Comments
 (0)