Created
June 24, 2021 15:58
-
-
Save Jayphen/28a5f5d02f218cd05704d929648ddb3e to your computer and use it in GitHub Desktop.
spy on a component but also keep its implementation
This file contains 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
// for when you REALLY need to test the props SomeComponent is rendered with (not recommended) | |
// create a mock that re-implements the default behaviour | |
// but allows us to spy on the props | |
jest.mock('components/SomeComponent', () => { | |
const original = jest.requireActual('components/SomeComponent') | |
return jest.fn(original.default) | |
}) | |
it('does the thing', () => { | |
render(<ThingThatRendersSomeComponent />) | |
expect(SomeComponent).toHaveBeenLastCalledWith( | |
// props | |
expect.objectContaining({ some: 'propValue' }), | |
// context | |
expect.anything() | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment