Skip to content

Commit 0a8c55c

Browse files
authored
Fix TemperatureControl test flake (#5045)
1 parent ae885d6 commit 0a8c55c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

webview-ui/src/components/settings/__tests__/TemperatureControl.spec.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npx vitest src/components/settings/__tests__/TemperatureControl.spec.tsx
22

3-
import { render, screen, fireEvent } from "@testing-library/react"
3+
import { render, screen, fireEvent, waitFor } from "@testing-library/react"
44

55
import { TemperatureControl } from "../TemperatureControl"
66

@@ -64,16 +64,18 @@ describe("TemperatureControl", () => {
6464
// Uncheck - should clear temperature.
6565
fireEvent.click(checkbox)
6666

67-
// Waiting for debounce.
68-
await new Promise((x) => setTimeout(x, 100))
69-
expect(onChange).toHaveBeenCalledWith(null)
67+
// Wait for debounced onChange call.
68+
await waitFor(() => {
69+
expect(onChange).toHaveBeenCalledWith(null)
70+
})
7071

7172
// Check - should restore previous temperature.
7273
fireEvent.click(checkbox)
7374

74-
// Waiting for debounce.
75-
await new Promise((x) => setTimeout(x, 100))
76-
expect(onChange).toHaveBeenCalledWith(0.7)
75+
// Wait for debounced onChange call.
76+
await waitFor(() => {
77+
expect(onChange).toHaveBeenCalledWith(0.7)
78+
})
7779
})
7880

7981
it("syncs checkbox state when value prop changes", () => {

0 commit comments

Comments
 (0)