-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 404 assertion to e2e error-boundary #506
Add 404 assertion to e2e error-boundary #506
Conversation
Thats clever, well done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just one thing.
tests/e2e/error-boundary.test.ts
Outdated
|
||
const listener = (request: Request) => { | ||
if (request.url().includes(pageUrl)) { | ||
request.response().then(response => expect(response?.status()).toBe(404)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With assertions that happen asynchronously like this I always like to make certain that they can fail. I'm concerned that as it's currently written, playwright will think the test is over before this assertion runs. Can you verify that the test can fail? https://kentcdodds.com/blog/make-your-test-fail
Ha excellent, I'll see if I can break the test tomorrow.
…On Mon, 30 Oct 2023, 22:26 Kent C. Dodds, ***@***.***> wrote:
***@***.**** commented on this pull request.
Thanks! Just one thing.
------------------------------
In tests/e2e/error-boundary.test.ts
<#506 (comment)>
:
>
await expect(page.getByText(/We can't find this page/i)).toBeVisible()
- // TODO: figure out how to assert the 404 status code
+
+ const listener = (request: Request) => {
+ if (request.url().includes(pageUrl)) {
+ request.response().then(response => expect(response?.status()).toBe(404))
With assertions that happen asynchronously like this I always like to make
certain that they can fail. I'm concerned that as it's currently written,
playwright will think the test is over before this assertion runs. Can you
verify that the test can fail?
https://kentcdodds.com/blog/make-your-test-fail
—
Reply to this email directly, view it on GitHub
<#506 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKELXJ6HXC753KUPT7HFYIDYCALQXAVCNFSM6AAAAAA6WVSVYWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMBVGEYDENRYGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I write like this in my code. Please share what is the problem here. test('Test root error boundary caught', async ({ page }) => {
const res = await page.goto('/does-not-exist')
expect(res?.status()).toBe(404)
await expect(page.getByText(/We can't find this page/i)).toBeVisible()
}) |
Ah, yes I definitely prefer that! |
Not sure if/why I didn't try that, suggestion applied. Another todo done ✅ |
Super! And have you verified that it can fail? |
It fails as soon as someone changes the return status in the loader from Is there anything else I should verify? |
Great! That's enough. Thank you! |
I noticed a
// todo: figure out
which seemed a nice little challenge. Add a listener to verify the 404Test Plan
Checklist