-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from alex-chew/setup-ui-testing
Set up UI tests with React Testing Library
- Loading branch information
Showing
7 changed files
with
204 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,23 @@ | ||
import React from 'react' | ||
import { Router } from 'react-router-dom' | ||
import { createMemoryHistory } from 'history' | ||
import { render } from '@testing-library/react' | ||
|
||
/* | ||
* Jest requires at least one test per file in __tests__. | ||
*/ | ||
test('', () => {}) | ||
|
||
/* | ||
* Wrapper around react-testing-library's `render` function, providing a dummy | ||
* Router. Implementation taken from the react-testing-library docs [1]. | ||
* | ||
* [1]: https://testing-library.com/docs/example-react-router | ||
*/ | ||
export const renderWithRouter = (ui, { | ||
route = '/', | ||
history = createMemoryHistory({ initialEntries: [route] }) | ||
} = {}) => ({ | ||
...render(<Router history={history}>{ui}</Router>), | ||
history | ||
}) |
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
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
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,27 @@ | ||
import React from 'react' | ||
import {cleanup} from '@testing-library/react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
import {renderWithRouter} from '__tests__/utils' | ||
|
||
import {fragments} from 'services/get-fragments' | ||
|
||
import {HomePage} from 'pages/Home' | ||
|
||
beforeEach(() => { | ||
// Mock fragment | ||
fragments.Home = { jsx: () => <p>Home mock</p> } | ||
}) | ||
|
||
afterEach(cleanup) | ||
|
||
test('Page renders', async () => { | ||
const { baseElement } = renderWithRouter(<HomePage />) | ||
expect(baseElement).toBeTruthy() | ||
}) | ||
|
||
test('Get Started link is visible', async () => { | ||
const rendered = renderWithRouter(<HomePage />) | ||
const gettingStartedLink = await rendered.findByTestId('gettingStartedLink') | ||
expect(gettingStartedLink).toBeVisible() | ||
}) |
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