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 | |
} |
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
// 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
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 | |
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
// 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 } from "./msw/mswHandlers"; | |
describe("<FancyHomePage />", () => { | |
beforeEach(() => setupHomeHandlers()); | |
test("displays homepage data", async () => { | |
// Render homepage with backend data | |
}); | |
}); |
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 | |
│ | |
└───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
// __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" })); | |
}) | |
); |
NewerOlder