Skip to content

Instantly share code, notes, and snippets.

@elmpp
Last active November 29, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmpp/5e44255ca75db8083af2fda186869187 to your computer and use it in GitHub Desktop.
Save elmpp/5e44255ca75db8083af2fda186869187 to your computer and use it in GitHub Desktop.
Jest: Mocking And Spying On A Class Dependency
// https://bambielli.com/til/2018-01-07-mocking-constructors/
const stackDriverSpy = jest.fn(() => ({}))
jest.genMockFromModule('@google-cloud/logging-winston')
jest.mock('@google-cloud/logging-winston')
const winstonLoggingModule = require('@google-cloud/logging-winston')
winstonLoggingModule.mockImplementation(stackDriverSpy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment