-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b17bed
commit ede24c9
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
exercises/05.errors/01.solution.composition/error-boundary.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen } = dtl | ||
|
||
import './index.tsx' | ||
|
||
testStep( | ||
'Error boundary is rendered immediately due to render error', | ||
async () => { | ||
// Check if the error message is displayed | ||
const errorMessage = await screen.findByRole('alert') | ||
expect(errorMessage).toBeDefined() | ||
expect(errorMessage.textContent).toContain('There was an error:') | ||
|
||
// Check if the error message contains the specific error | ||
const errorDetails = await screen.findByText(/invalid time/i) | ||
expect(errorDetails).toBeDefined() | ||
|
||
// Ensure the form is not rendered | ||
const form = screen.queryByRole('form') | ||
expect(form).toBeNull() | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
exercises/05.errors/02.solution.show-boundary/error-boundary.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen } = dtl | ||
import { userEvent } from '@testing-library/user-event' | ||
|
||
const user = userEvent.setup() | ||
|
||
import './index.tsx' | ||
|
||
testStep('Error boundary is rendered after form submission', async () => { | ||
// submit the form | ||
await user.click(await screen.findByRole('button', { name: /submit/i })) | ||
|
||
// Check if the error message is displayed | ||
const errorMessage = await screen.findByRole('alert') | ||
expect(errorMessage).toBeDefined() | ||
expect(errorMessage.textContent).toContain('There was an error:') | ||
|
||
// Check if the error message contains the specific error | ||
const errorDetails = await screen.findByText(/toUpperCase/i) | ||
expect(errorDetails).toBeDefined() | ||
|
||
// Ensure the form is not rendered after error | ||
const form = screen.queryByRole('form') | ||
expect(form).toBeNull() | ||
}) |
41 changes: 41 additions & 0 deletions
41
exercises/05.errors/03.solution.reset/error-boundary.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen } = dtl | ||
import { userEvent } from '@testing-library/user-event' | ||
|
||
const user = userEvent.setup() | ||
|
||
import './index.tsx' | ||
|
||
testStep('Error boundary is rendered after form submission', async () => { | ||
// submit the form | ||
await user.click(await screen.findByRole('button', { name: /submit/i })) | ||
|
||
// Check if the error message is displayed | ||
const errorMessage = await screen.findByRole('alert') | ||
expect(errorMessage).toBeDefined() | ||
expect(errorMessage.textContent).toContain('There was an error:') | ||
|
||
// Check if the error message contains the specific error | ||
const errorDetails = await screen.findByText(/toUpperCase/i) | ||
expect(errorDetails).toBeDefined() | ||
|
||
// Ensure the form is not rendered after error | ||
const form = screen.queryByRole('form') | ||
expect(form).toBeNull() | ||
}) | ||
|
||
testStep('Clicking "Try again" resets the error boundary', async () => { | ||
// Click the "Try again" button | ||
const tryAgainButton = await screen.findByRole('button', { | ||
name: /try again/i, | ||
}) | ||
await user.click(tryAgainButton) | ||
|
||
// Verify that the submit button appears again | ||
const submitButton = await screen.findByRole('button', { name: /submit/i }) | ||
expect(submitButton).toBeDefined() | ||
|
||
// Ensure the error message is no longer present | ||
const errorMessage = screen.queryByRole('alert') | ||
expect(errorMessage).toBeNull() | ||
}) |