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 { server } from '../tools/jest/server'; | |
| //... | |
| export const setupFaultyHomeHandlers = () => { | |
| server.use( | |
| rest.get('https://fancy-app.com/homepage-data', (_req, res, ctx) => { |
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, | |
| setupFaultyHomeHandlers, | |
| setupFailedHomeHandlers, | |
| } from "./msw/mswHandlers"; | |
| describe("<FancyHomePage />", () => { | |
| beforeEach(() => setupHomeHandlers()); |
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
| export const setupSmartMswHelper = (override = {}) => { | |
| server.use( | |
| rest.get("https://fancy-app.com/return-some-data", (req, res, ctx) => { | |
| return res( | |
| ctx.status(200), | |
| ctx.json({ | |
| fancyData: "Im so fancy!", | |
| moreData: "You already know", | |
| ...override, | |
| }) |
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 | |
| //... | |
| test("handles updated data", async () => { | |
| setupSmartMswHelper({ | |
| moreData: "Cant you taste this gold?", | |
| }); | |
| //... | |
| }); |
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
| // tools/jest/setupTests.js | |
| const error = console.error; | |
| console.error = (...args) => | |
| // Suppress error messages regarding network error in tests | |
| /Error: Request failed with status code 500/m.test( | |
| args[0] | |
| ) | |
| ? void 0 | |
| : error(...args); |
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
| theme: { | |
| /* ... */ | |
| version: 3 | 2 | |
| } |
OlderNewer