Skip to content

Instantly share code, notes, and snippets.

@asci
Created April 9, 2019 10:01
Show Gist options
  • Save asci/0fd7ebebc06961843fc8f89ebb3ca257 to your computer and use it in GitHub Desktop.
Save asci/0fd7ebebc06961843fc8f89ebb3ca257 to your computer and use it in GitHub Desktop.
Jest mocks snippets
// 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