Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
jest-launchdarkly-mock
Advanced tools
Changelog
[2.1.0] - 2023-06-06
Readme
Easily unit test LaunchDarkly feature flagged components with jest :clap:
This package is only compatible with the react sdk.
yarn add -D jest-launchdarkly-mock
or
npm install jest-launchdarkly-mock --save-dev
Then in jest.config.js
add jest-launchdarkly-mock to setupFiles:
// jest.config.js
module.exports = {
setupFiles: ['jest-launchdarkly-mock'],
}
Use the only 3 apis for test cases:
mockFlags(flags: LDFlagSet)
: mock flags at the start of each test case. Only mocks
flags returned by the useFlags
hook.
ldClientMock
: a jest mock of the ldClient. All
methods of this object are jest mocks.
resetLDMocks
: resets both mockFlags and ldClientMock.
import { mockFlags, ldClientMock, resetLDMocks } from 'jest-launchdarkly-mock'
describe('button', () => {
beforeEach(() => {
// reset before each test case
resetLDMocks()
})
test('flag on', () => {
// arrange
// You can use the original unchanged case, kebab-case, camelCase or snake_case keys.
mockFlags({ devTestFlag: true })
// act
const { getByTestId } = render(<Button />)
// assert
expect(getByTestId('test-button')).toBeTruthy()
})
test('identify', () => {
// arrange
mockFlags({ 'dev-test-flag': true })
// act
const { getByTestId } = render(<Button />)
fireEvent.click(getByTestId('test-button'))
// assert: identify gets called
expect(ldClientMock.identify).toBeCalledWith({ key: 'aa0ceb' })
})
})
FAQs
Easily unit test LaunchDarkly feature flagged components with jest
The npm package jest-launchdarkly-mock receives a total of 111,109 weekly downloads. As such, jest-launchdarkly-mock popularity was classified as popular.
We found that jest-launchdarkly-mock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.