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
| import { render, screen, waitFor } from "@testing-library/react"; | |
| import userEvent from "@testing-library/user-event"; | |
| import { rest } from "msw"; | |
| import CONSTANTS from "../../constants"; | |
| import IPost from "../../interfaces/Post"; | |
| import server from "../../mocks/server"; | |
| import PostItem from "./PostItem"; | |
| const post: IPost = { | |
| id: 1, |
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
| function getComments() { | |
| return rest.get(`${CONSTANTS.API_URL}/comments`, (req, res, ctx) => { | |
| return res( | |
| ctx.status(200), | |
| ctx.json([ | |
| { | |
| id: 1, | |
| name: "Comment name 1", | |
| email: "richosojason@msn.com", | |
| body: "Comment body 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
| import React from "react"; | |
| import { render, screen } from "@testing-library/react"; | |
| import Posts from "./Posts"; | |
| import server from "../../mocks/server"; | |
| import { rest } from "msw"; | |
| import CONSTANTS from "../../constants"; | |
| describe("Posts test suite", () => { | |
| test("Renders the component with loading state", async () => { | |
| render(<Posts />); |
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
| import server from "./mocks/server"; | |
| beforeAll(() => server.listen()); | |
| afterEach(() => server.resetHandlers()); | |
| afterAll(() => server.close()); |
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
| import { setupServer } from "msw/node"; | |
| import { handlers } from "./handlers"; | |
| const server = setupServer(...handlers); | |
| export default server; |
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
| import { rest } from "msw"; | |
| import CONSTANTS from "../constants"; | |
| function getPosts() { | |
| return rest.get(`${CONSTANTS.API_URL}/posts`, (req, res, ctx) => { | |
| return res( | |
| ctx.status(200), | |
| ctx.json([ | |
| { | |
| userId: 1, |
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
| const mockedFetch = jest.fn(() => | |
| Promise.resolve({ | |
| json: () => Promise.resolve({}), | |
| }) | |
| ) as jest.Mock; | |
| global.fetch = mockedFetch; | |
| test("Renders the component with posts", async () => { | |
| render(<Posts />); |
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
| import { Helicopter } from "./mixins"; | |
| class Vehicle { | |
| constructor(public color: string) {} | |
| protected honk(): void { | |
| console.log("beep"); | |
| } | |
| } |
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
| <Formik | |
| initialValues={initialValues} | |
| onSubmit={onSubmit} | |
| validationSchema={validationSchema} | |
| > | |
| <Form className="form"> | |
| <label htmlFor="firstName" className="form__label"> | |
| First Name | |
| </label> | |
| <Field |
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
| import * as yup from "yup"; | |
| const isRequiredMessage = "This field is required"; | |
| export default yup.object().shape({ | |
| firstName: yup.string().required(isRequiredMessage).max(10), | |
| lastName: yup.string().optional().max(10), | |
| email: yup.string().required(isRequiredMessage).email(), | |
| }); |
NewerOlder