Skip to content

Commit

Permalink
mock pluralize for whole test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mercedesb committed Jul 12, 2020
1 parent e2e9a37 commit ab59ab4
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 30 deletions.
6 changes: 0 additions & 6 deletions src/components/__tests__/Breadcrumbs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ jest.mock("react-router-dom", () => ({
}),
}));

// to mock a default export without an object
// mock the module
// add a mockImplementation or mockReturn value in your test
jest.mock("pluralize", () => jest.fn());

let subject;

describe("Breadcrumbs", () => {
beforeEach(() => {
pluralize.mockReturnValue(mockAnimal);
subject = (
<MemoryRouter>
<Breadcrumbs />
Expand Down
6 changes: 0 additions & 6 deletions src/components/__tests__/DisplayAnimalContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import { DisplayAnimalContainer } from "../DisplayAnimalContainer";
let mockUseContext = jest.fn(() => ({ animals: mockAnimals }));
jest.spyOn(React, "useContext").mockImplementation(mockUseContext);

let mockPluralize = jest.fn((word) => word);
jest.mock("pluralize", () => ({
__esModule: true,
default: (word) => mockPluralize(word),
}));

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"), // use actual for all non-hook parts
useParams: jest.fn(),
Expand Down
6 changes: 0 additions & 6 deletions src/components/__tests__/FetchingContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ let renderFn = jest.fn();
let mockUseContext = jest.fn(() => ({ animals: mockAnimals }));
jest.spyOn(React, "useContext").mockImplementation(mockUseContext);

let mockPluralize = jest.fn((word) => word);
jest.mock("pluralize", () => ({
__esModule: true,
default: (word) => mockPluralize(word),
}));

afterEach(() => {
jest.clearAllMocks();
cleanup();
Expand Down
6 changes: 0 additions & 6 deletions src/components/__tests__/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ let subject;
let mockUseContext = jest.fn(() => ({ animals: mockAnimals }));
jest.spyOn(React, "useContext").mockImplementation(mockUseContext);

let mockPluralize = jest.fn((word) => word);
jest.mock("pluralize", () => ({
__esModule: true,
default: (word) => mockPluralize(word),
}));

describe("Home", () => {
describe("render", () => {
beforeEach(() => {
Expand Down
6 changes: 0 additions & 6 deletions src/components/__tests__/SeeOthers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ jest.mock("react-router-dom", () => ({
let mockUseContext = jest.fn(() => ({ animals: mockAnimals }));
jest.spyOn(React, "useContext").mockImplementation(mockUseContext);

let mockPluralize = jest.fn((word) => word);
jest.mock("pluralize", () => ({
__esModule: true,
default: (word) => mockPluralize(word),
}));

describe("SeeOthers", () => {
describe("render", () => {
beforeEach(() => {
Expand Down
5 changes: 5 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import "@testing-library/jest-dom/extend-expect";
import { cleanup } from "@testing-library/react";
import { SessionStorageMock } from "./testHelpers/sessionStorageMock";

jest.mock("pluralize", () => ({
__esModule: true,
default: jest.fn((word) => word),
}));

const unmockedSessionStorage = global.sessionStorage;

beforeAll(() => {
Expand Down

0 comments on commit ab59ab4

Please sign in to comment.