Skip to content

Commit fe829eb

Browse files
committed
03/04: remove waitFor from assertion
1 parent 0e8c217 commit fe829eb

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

exercises/03.best-practices/04.solution.inverse-assertions/README.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Problem: testing things that must _not_ appear on the page can lead to false-positive tests in no time. Let's learn about _inverse assertions_ that help you write such tests reliably.
44

5+
> Note: Vitest's `expect.element()` already has a built-in retry mechanism.
6+
57
## Materials
68

79
- [Inverse assertions](https://www.epicweb.dev/inverse-assertions)

exercises/03.best-practices/04.solution.inverse-assertions/src/discount-code-form.browser.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,5 @@ test('removes the applied discount code', async () => {
9797
})
9898
await removeDiscountButton.click()
9999

100-
await vi.waitFor(async () => {
101-
await expect.element(discountText).not.toBeInTheDocument()
102-
})
100+
await expect.element(discountText).not.toBeInTheDocument()
103101
})

exercises/03.best-practices/04.solution.inverse-assertions/src/mocks/handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http, HttpResponse } from 'msw'
1+
import { delay, http, HttpResponse } from 'msw'
22
import type { Discount } from '../discount-code-form.js'
33

44
export const handlers = [
@@ -14,6 +14,7 @@ export const handlers = [
1414
},
1515
),
1616
http.delete('https://api.example.com/discount/code', async () => {
17+
await delay(500)
1718
return new HttpResponse()
1819
}),
1920
]

0 commit comments

Comments
 (0)