Skip to content
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

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

SanderKoopmans
Copy link
Contributor

I noticed a // todo: figure out which seemed a nice little challenge. Add a listener to verify the 404

Test Plan

  • Checkout branch
  • Run e2e tests

Checklist

  • [ x ] Tests updated
  • [ n/a ] Docs updated

@swalker326
Copy link
Contributor

Thats clever, well done.

Copy link
Member

@kentcdodds kentcdodds left a 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.


const listener = (request: Request) => {
if (request.url().includes(pageUrl)) {
request.response().then(response => expect(response?.status()).toBe(404))
Copy link
Member

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

@SanderKoopmans
Copy link
Contributor Author

SanderKoopmans commented Oct 30, 2023 via email

@caprolactam
Copy link
Contributor

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()
})

ref

@kentcdodds
Copy link
Member

Ah, yes I definitely prefer that!

@SanderKoopmans
Copy link
Contributor Author

Not sure if/why I didn't try that, suggestion applied. Another todo done ✅

@kentcdodds
Copy link
Member

Super! And have you verified that it can fail?

@SanderKoopmans
Copy link
Contributor Author

It fails as soon as someone changes the return status in the loader from routes/$.tsx. Second part fails as soon as someone changes the statusHandlers from the error boundary.

Is there anything else I should verify? ☺️

@kentcdodds
Copy link
Member

Great! That's enough. Thank you!

@kentcdodds kentcdodds merged commit 7417c50 into epicweb-dev:main Oct 31, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants