This file contains hidden or 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
| yarn add --dev reassure | |
| # or | |
| npm install --save-dev reassure |
This file contains hidden or 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
| // counter.perf-test.tsx | |
| test('Count increments on press', async () => { | |
| const scenario = async (screen: RenderAPI) => { | |
| const button = screen.getByText('Action'); | |
| await screen.findByText('Count: 0’); | |
| fireEvent.press(button); | |
| fireEvent.press(button); | |
| await screen.findByText('Count: 2'); | |
| }; |
This file contains hidden or 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
| # Gather baseline perf measurements | |
| git switch main | |
| yarn install --force | |
| yarn reassure --baseline | |
| # Gather current perf measurements & compare results | |
| git switch - | |
| yarn install --force | |
| yarn reassure |
This file contains hidden or 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
| // src/mocks/handlers.js | |
| import { rest } from "msw"; | |
| export const handlers = [ | |
| // Handles a POST request | |
| rest.post("https://fancy-app.com/postToThisEndpoint", (req, res, ctx) => { | |
| return res( | |
| // Respond with a 200 status code | |
| ctx.status(200) | |
| ); |
This file contains hidden or 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
| // src/mocks/server.js | |
| import { setupServer } from 'msw/node' | |
| import { handlers } from './handlers' | |
| // This configures a request mocking server with the given request handlers. | |
| export const server = setupServer(...handlers) |
This file contains hidden or 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
| // src/setupTests.js | |
| import { server } from './mocks/server.js' | |
| // Establish API mocking before all tests. | |
| beforeAll(() => server.listen()) | |
| // Reset any request handlers that we may add during the tests, | |
| // so they don't affect other tests. | |
| afterEach(() => server.resetHandlers()) | |
| // Clean up after the tests are finished. |
This file contains hidden or 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
| // __tests__/FancyPage.test.js | |
| import { setupServer } from "msw/node"; | |
| import { FancyComponentWithAPICall } from "../FancyComponentWithAPICall"; | |
| const server = setupServer( | |
| rest.get("https://fancy-app.com/getSomeData", (req, res, ctx) => { | |
| return res(ctx.json({ data: "return this string" })); | |
| }) | |
| ); |
This file contains hidden or 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
| src | |
| │ | |
| └───tools | |
| | └───jest | |
| │ │ commonMswHandlers.js | |
| │ │ server.js | |
| | | setupTests.js | |
| │ | |
| └───featureA | |
| │ │ FeatureA.js |
This file contains hidden or 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
| // src/FancyHomepageFeature/msw/mswHandlers.js | |
| import { rest } from 'msw'; | |
| // import the server created for the entire test suite | |
| // this mock server includes commonMswHandlers | |
| import { server } from '../tools/jest/server'; | |
| const homeHandlers = [ | |
| rest.get('https://fancy-app.com/homepage-data', (req, res, ctx) => { | |
| return res( |
This file contains hidden or 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
| // src/FancyHomepageFeature/__tests__/FancyHomePage.test.js | |
| import { FancyHomePage } from "../FancyHomePage"; | |
| import { setupHomeHandlers } from "./msw/mswHandlers"; | |
| describe("<FancyHomePage />", () => { | |
| beforeEach(() => setupHomeHandlers()); | |
| test("displays homepage data", async () => { | |
| // Render homepage with backend data | |
| }); | |
| }); |
OlderNewer