Replace manual checks with web-first assertions
beginner Assertions Challenge 9 of 22
This test is meant to check that saving the profile shows a “Profile saved” status message. It passes on CI even when the message never appears. Rewrite the assertions so the test is honest and stable.
Requirements
- Do not use
isVisible(), and do not put assertions inside anif. - Assert that the status message is visible with
await expect(...).toBeVisible(). - Assert its text with
toHaveTextortoContainText. - Do not read text manually with
textContent()orinnerText().
Expected output
The test asserts unconditionally with `await expect(locator).toBeVisible()` and `toHaveText(...)`, which retry until the toast appears or the timeout expires.
Scenarios (4)
Your tests run once against each version of the demo app. They must pass on the working app and fail on every version with a planted bug.
- ○Working app · must pass
- ○Slow API · must pass · API 1200ms
- ○Bug: no confirmation · must catch
- ○Bug: wrong message · must catch
Checks (5)
- ○Does not snapshot visibility with isVisible()
- ○Uses an awaited web-first expect(locator)
- ○Asserts visibility with toBeVisible()
- ○Asserts the message with toHaveText() or toContainText()
- ○Does not read text manually
example.spec.tsRuns against a live demo app
Ctrl/⌘ + Enter to run tests · your code is saved in this browser
Results
Run the tests to see results here.
Demo app
The working app. You can click around it; your tests start from a fresh copy.