Skip to content

Prevent resetMocks: true from clearing mock implementations#58

Open
michaeldfallen wants to merge 1 commit intolaunchdarkly:mainfrom
THE-Engineering:jest-resetMocks-fix
Open

Prevent resetMocks: true from clearing mock implementations#58
michaeldfallen wants to merge 1 commit intolaunchdarkly:mainfrom
THE-Engineering:jest-resetMocks-fix

Conversation

@michaeldfallen
Copy link
Copy Markdown

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Describe the solution you've provided

If a team uses resetMocks: true in their jest config then the mocked functions of launchdarkly-react-client-sdk will return undefined during test execution.

To allow teams using resetMocks to use this package I have pulled the mock implementations into a setupMocks function that can be called in beforeEach.

I haven't updated the documentation to explain this usecase, I'd value feedback on where / how to do that.

@yusinto
Copy link
Copy Markdown
Contributor

yusinto commented Jun 21, 2023

Thank you for submitting this PR. We will review and provide an update soon.

Copy link
Copy Markdown
Contributor

@yusinto yusinto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Please also update the readme with instructions on how to use the new setupLDMocks function.

Comment thread src/index.ts
mockWithLDConsumer.mockImplementation(() => (children: any) => children)
mockWithLDProvider.mockImplementation(() => (children: any) => children)
/* eslint-enable @typescript-eslint/no-explicit-any */
export const setupMocks = () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with resetLDMocks, can you please rename this to setupLDMocks?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants