Skip to content

Commit 3e1e1c1

Browse files
Refactor test: use step helper called from template instead of DOM assertions
Agent-Logs-Url: https://github.com/emberjs/ember.js/sessions/509a66ed-dd19-4b09-aadc-523e8e19e5f6 Co-authored-by: NullVoxPopuli <[email protected]>
1 parent 3a93b79 commit 3e1e1c1

1 file changed

Lines changed: 13 additions & 33 deletions

File tree

packages/@glimmer-workspace/integration-tests/lib/suites/in-element-document-fragment.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,64 +136,44 @@ export class InElementDocumentFragmentSuite extends RenderTest {
136136
'After fragment is attached to DOM, text updates and new conditional elements appear in the container'() {
137137
const fragment = document.createDocumentFragment();
138138
const container = document.createElement('div');
139+
const step = (text: string) => this.assert.step(text);
139140

140141
this.render(
141142
'{{#in-element this.fragment}}' +
142-
'<p id="msg">{{this.message}}</p>' +
143-
'{{#if this.show}}<span id="extra">extra</span>{{/if}}' +
143+
'<p id="msg">{{this.message}} {{this.step "message rendered"}}</p>' +
144+
'{{#if this.show}}' +
145+
'<span id="extra">extra {{this.step "extra rendered"}}</span>' +
146+
'{{/if}}' +
144147
'{{/in-element}}',
145148
{
146149
fragment,
147150
message: 'initial',
148151
show: false,
152+
step,
149153
}
150154
);
151155

152-
this.assert.step('initial render into fragment');
153-
const p = fragment.querySelector('#msg') as HTMLElement;
154-
this.assert.strictEqual(p?.textContent, 'initial', 'p rendered in fragment');
155-
this.assert.notOk(fragment.querySelector('#extra'), 'no extra span in fragment yet');
156+
this.assert.verifySteps(['message rendered'], 'initial render fires step from inside fragment');
156157

157158
// Move fragment's children (including Glimmer's comment bounds) into the container
158159
container.appendChild(fragment);
159-
this.assert.step('fragment attached to DOM');
160160
this.assert.strictEqual(fragment.childNodes.length, 0, 'fragment is empty after append');
161-
this.assert.strictEqual(
162-
container.querySelector('#msg')?.textContent,
163-
'initial',
164-
'p is in the container'
165-
);
166161

167162
// Text-node update: Glimmer holds a direct reference to the text node, so the
168163
// update is visible in the container even though the fragment is now empty.
169164
this.rerender({ message: 'updated' });
170-
this.assert.step('text updated');
171-
this.assert.strictEqual(
172-
container.querySelector('#msg')?.textContent,
173-
'updated',
174-
'text update is reflected in the container'
165+
this.assert.verifySteps(
166+
['message rendered'],
167+
'text update fires step even after fragment was attached to the DOM'
175168
);
176-
this.assert.strictEqual(fragment.childNodes.length, 0, 'fragment remains empty after text update');
177169

178170
// New-element update: Glimmer inserts the span relative to the comment bounds,
179171
// which also moved to the container, so the new element appears in the container.
180172
this.rerender({ show: true });
181-
this.assert.step('conditional element shown');
182-
this.assert.ok(
183-
container.querySelector('#extra'),
184-
'new conditional element appears in the container (comment bounds moved with the fragment)'
185-
);
186-
this.assert.notOk(
187-
fragment.querySelector('#extra'),
188-
'new conditional element is not in the (now-empty) fragment'
173+
this.assert.verifySteps(
174+
['message rendered', 'extra rendered'],
175+
'new conditional element fires step in the container after fragment was attached to the DOM'
189176
);
190-
191-
this.assert.verifySteps([
192-
'initial render into fragment',
193-
'fragment attached to DOM',
194-
'text updated',
195-
'conditional element shown',
196-
]);
197177
}
198178

199179
@test

0 commit comments

Comments
 (0)