All Projects → launchdarkly-labs → jest-launchdarkly-mock

launchdarkly-labs / jest-launchdarkly-mock

Licence: Apache-2.0 License
Easily unit test LaunchDarkly feature flagged components with jest

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to jest-launchdarkly-mock

ld-redux
A library to integrate launch darkly with react redux
Stars: ✭ 33 (+135.71%)
Mutual labels:  feature-flags, feature-toggles, flags, feature, launchdarkly
ld-scheduler
Schedule Launch Darkly flags on or off
Stars: ✭ 14 (+0%)
Mutual labels:  feature-flags, feature-toggles, flags, feature, launchdarkly
Unleash
Unleash is the open source feature toggle service.
Stars: ✭ 4,679 (+33321.43%)
Mutual labels:  feature-flags, feature-toggles, feature
Unleash Client Go
Unleash Client for Go
Stars: ✭ 78 (+457.14%)
Mutual labels:  feature-flags, feature-toggles, feature
unleash-client-java
Unleash client SDK for Java
Stars: ✭ 86 (+514.29%)
Mutual labels:  feature-flags, feature-toggles, feature
Flagception Bundle
Feature flags on steroids!
Stars: ✭ 162 (+1057.14%)
Mutual labels:  feature-flags, feature-toggles, feature
ios-client-sdk
LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
Stars: ✭ 45 (+221.43%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
Flipper
🐬 Beautiful, performant feature flags for Ruby.
Stars: ✭ 2,732 (+19414.29%)
Mutual labels:  feature-flags, feature-toggles, feature
ruby-server-sdk
LaunchDarkly Server-side SDK for Ruby
Stars: ✭ 25 (+78.57%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
php-server-sdk
LaunchDarkly Server-side SDK for PHP
Stars: ✭ 31 (+121.43%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
java-server-sdk
LaunchDarkly Server-Side SDK for Java
Stars: ✭ 71 (+407.14%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
erlang-server-sdk
LaunchDarkly Server-Side SDK for Erlang/Elixir
Stars: ✭ 16 (+14.29%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
Vuex Mock Store
✅Simple and straightforward Vuex Store mock for vue-test-utils
Stars: ✭ 246 (+1657.14%)
Mutual labels:  mock, jest, test
js-client-sdk
LaunchDarkly Client-side SDK for Browser JavaScript
Stars: ✭ 93 (+564.29%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
node-mock-examples
Examples of tests that mock Node system APIs: fs, http, child_process, timers
Stars: ✭ 38 (+171.43%)
Mutual labels:  mock, test
unleash-docker
Docker container for unleash
Stars: ✭ 89 (+535.71%)
Mutual labels:  feature-flags, feature-toggles
laravel-rollout
A package to integrate rollout into your Laravel project.
Stars: ✭ 23 (+64.29%)
Mutual labels:  feature-flags, feature-toggles
nestjs-config
NestJS Module for Nonfig services. Nonfig combines Configurations and Features. So you change features, and release swiftly, and measure to digital impact.
Stars: ✭ 40 (+185.71%)
Mutual labels:  feature-flags, feature-toggles
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (+607.14%)
Mutual labels:  mock, test
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+4100%)
Mutual labels:  jest, test

jest-launchdarkly-mock

npm version npm downloads License PRs Welcome

Star on GitHub Tweet

Easily unit test LaunchDarkly feature flagged components with jest 👏

This package is only compatible with the react sdk.

Installation

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'],
}

Usage

Use the only 3 apis for test cases:

  • mockFlags(flags: LDFlagSet): mock flags at the start of each test case.

  • ldClientMock: a jest mock of the ldClient. All methods of this object are jest mocks.

  • resetLDMocks : resets both mockFlags and ldClientMock.

Example

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' })
  })
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].