Created
April 9, 2019 10:01
-
-
Save asci/0fd7ebebc06961843fc8f89ebb3ca257 to your computer and use it in GitHub Desktop.
Jest mocks snippets
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
// Mock default constructor | |
import SomeConstructor from "some-package" | |
const SomePackageMock = { | |
default: jest.fn(), | |
} | |
jest.mock("some-package", () => SomePackageMock) | |
// Import place where construcor from some-package is used | |
import { testStuff } from "../Scroll/useElementSize" | |
test("stuff", () => { | |
SomePackageMock.default.mockImplementationOnce(function(): any { | |
// here mocked implementation goes | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment