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
import React from "react"; | |
import { render } from "@testing-library/react"; | |
import { Props } from "."; | |
import { Default } from "./index.stories"; | |
test("should render the title", () => { | |
const props = Default.args as Props; | |
const { getByText } = render(<Default {...props} />); | |
const actual = getByText(props.title); | |
expect(actual).toBeInTheDocument(); |
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
import React from "react"; | |
import { render } from "@testing-library/react"; | |
import { Props } from "."; | |
import { Default } from "./index.stories"; | |
describe("COMPONENT_NAME", () => { | |
describe("Default", () => { | |
const props = Default.args as Props; | |
test("should match snapshot", () => { |
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
import { axe } from "jest-axe"; | |
test("should be accessible", async () => { | |
const { container } = render(<Component />); | |
expect(await axe(container)).toHaveNoViolations(); | |
}); |
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
import React from "react"; | |
import * as stories from "./index.stories"; | |
import { axe } from "jest-axe"; | |
import userEvent from "@testing-library/user-event"; | |
import { composeStories } from "@storybook/testing-react"; | |
import { render, screen } from "@testing-library/react"; | |
const { Default } = composeStories(stories); | |
describe("MyComponent", () => { |
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
test("should match snapshot", () => { | |
const { container } = render(<Default {...props} />); | |
expect(container.firstChild).toMatchSnapshot(); | |
}); |
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
test("should be accessible and match snapshot", async () => { | |
const { container } = render(<Default {...props} />); | |
expect(await axe(container)).toHaveNoViolations(); | |
expect(container.firstChild).toMatchSnapshot(); | |
}); |
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
jest.mock("react-modal", () => ({ children }: any) => children); |
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
const server = setupServer( | |
rest.get("/jobs", (req, res, ctx) => res(ctx.json(fixtures.jobs))), | |
); | |
beforeAll(() => server.listen({ onUnhandledRequest: "error" })); | |
afterAll(() => server.close()); | |
afterEach(() => server.resetHandlers()); |
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
import { ComponentMeta } from "@storybook/react"; | |
import COMPONENT_NAME from "."; | |
import { userEvent, within } from "@storybook/testing-library"; | |
export default { | |
component: COMPONENT_NAME, | |
decorators: [(story) => <div>{story()}</div>], | |
parameters: { | |
layout: "centered", | |
}, |
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
// Flexible Compound Components - epicreact.dev | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
// 📜 https://reactjs.org/docs/context.html#reactcreatecontext | |
const ToggleContext = React.createContext() | |
ToggleContext.displayName = 'ToggleContext' | |
function Toggle({children}) { |