Skip to content

Instantly share code, notes, and snippets.

@mergebandit
Last active May 26, 2020 19:54
Show Gist options
  • Save mergebandit/2b871bada6051c09b4fff84d77982920 to your computer and use it in GitHub Desktop.
Save mergebandit/2b871bada6051c09b4fff84d77982920 to your computer and use it in GitHub Desktop.
TIL-Lab49/Clearing Jest Mocks

Mocking Services

When mocking services in jest, given:

const someMethodMock = mockService.someMethod as jest.Mock;
beforeEach(() => {
  jest.clearAllMocks()
})

Calling jest.clearAllMocks does not work as expected. Instead, you have to write:

beforeEach(() => {
  someMethodMock.mockReset()
})

This is a known issue with jest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment