Skip to content

Commit 7001649

Browse files
committed
fix: ensure maquette renders between fill and keypress to prevent flaky test
Maquette only updates the DOM input value if it differs from the previous render's value (to preserve cursor position). When fill() and press('Enter') happen without an intervening render, this race condition occurs: 1. Initial render has value: '', previousValue = '' 2. fill() sets DOM value, schedules render 3. press('Enter') fires BEFORE animation frame 4. Handler clears newTodoTitle to '' 5. Render happens with value: '' 6. propValue ('') === previousValue (''), so DOM is NOT updated! The fix adds a waitForAnimationFrame() after fill() to ensure maquette renders the filled value before pressing Enter, so previousValue is updated.
1 parent fccbc33 commit 7001649

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

browser-tests/tests/TodoPage.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ export class TodoPage {
3636
}
3737

3838
/**
39-
* Wait for one animation frame to allow maquette to render
39+
* Wait for two animation frames to allow maquette to render
4040
*/
4141
async waitForAnimationFrame(): Promise<void> {
4242
await this.page.evaluate(
43-
() => new Promise((resolve) => requestAnimationFrame(() => resolve(undefined)))
43+
() =>
44+
new Promise((resolve) =>
45+
requestAnimationFrame(() => requestAnimationFrame(() => resolve(undefined)))
46+
)
4447
);
4548
}
4649

@@ -72,8 +75,13 @@ export class TodoPage {
7275
*/
7376
async addTodo(text: string): Promise<void> {
7477
await this.newTodoInput.fill(text);
78+
// Wait for maquette to render the filled value before pressing Enter.
79+
// This is important because maquette only updates the DOM value if it
80+
// differs from the previous render. Without this wait, the Enter keypress
81+
// could happen before maquette renders, causing it to skip the DOM update.
82+
await this.waitForAnimationFrame();
7583
await this.newTodoInput.press("Enter");
76-
// Wait for maquette to render
84+
// Wait for maquette to render after clearing
7785
await this.waitForAnimationFrame();
7886
}
7987

0 commit comments

Comments
 (0)