@launchdarkly/jest 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +59 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.0](https://github.com/launchdarkly/js-core/compare/jest-v0.2.2...jest-v1.0.0) (2026-02-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* updating to major version 1 ([#1089](https://github.com/launchdarkly/js-core/issues/1089))
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* updating to major version 1 ([#1089](https://github.com/launchdarkly/js-core/issues/1089)) ([4c194d8](https://github.com/launchdarkly/js-core/commit/4c194d8112d39e3693688c0cbe0bc7ef27b67869))
|
|
13
|
+
|
|
3
14
|
## [0.2.2](https://github.com/launchdarkly/js-core/compare/jest-v0.2.1...jest-v0.2.2) (2026-01-21)
|
|
4
15
|
|
|
5
16
|
|
package/README.md
CHANGED
|
@@ -6,23 +6,24 @@
|
|
|
6
6
|
[![NPM][jest-dm-badge]][jest-npm-link]
|
|
7
7
|
[![NPM][jest-dt-badge]][jest-npm-link]
|
|
8
8
|
|
|
9
|
-
> [!CAUTION]
|
|
10
|
-
> This library is a beta version and should not be considered ready for production use while this message is visible.
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
**Easily unit test LaunchDarkly feature flagged applications with jest**
|
|
13
12
|
|
|
14
13
|
For more information, see the [complete reference guide for unit testing](https://docs.launchdarkly.com/guides/sdk/unit-tests).
|
|
15
14
|
|
|
16
15
|
## Installation
|
|
17
16
|
|
|
18
|
-
```
|
|
19
|
-
# npm
|
|
20
|
-
npm i @launchdarkly/jest --save-dev
|
|
21
|
-
|
|
22
|
-
# yarn
|
|
17
|
+
```bash
|
|
23
18
|
yarn add -D @launchdarkly/jest
|
|
24
19
|
```
|
|
25
20
|
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @launchdarkly/jest --save-dev
|
|
25
|
+
```
|
|
26
|
+
|
|
26
27
|
Then in `jest.config.js` add `@launchdarkly/jest/{framework}` to setupFiles:
|
|
27
28
|
|
|
28
29
|
```js
|
|
@@ -33,34 +34,59 @@ module.exports = {
|
|
|
33
34
|
};
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
##
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
Use these 3 APIs for your test cases:
|
|
40
|
+
|
|
41
|
+
- `mockFlags(flags: LDFlagSet)`: Mock flags at the start of each test case. Only mocks flags returned by the `useFlags` hook.
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
- `getLDClient()`: Returns a jest mock of the [LDClient](https://launchdarkly.github.io/js-core/packages/shared/sdk-client/docs/classes/LDClientImpl.html). All methods of this object are jest mocks.
|
|
44
|
+
|
|
45
|
+
- `resetLDMocks()`: Resets both mockFlags and getLDClient mocks.
|
|
46
|
+
|
|
47
|
+
## Example
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
39
50
|
import React from 'react';
|
|
40
|
-
import { render } from '@testing-library/react-native';
|
|
41
|
-
import {
|
|
42
|
-
mockFlags,
|
|
43
|
-
resetLDMocks,
|
|
44
|
-
getLDClient,
|
|
45
|
-
} from '@launchdarkly/js-core/tooling/jest';
|
|
51
|
+
import { render, fireEvent } from '@testing-library/react-native';
|
|
52
|
+
import { mockFlags, resetLDMocks, getLDClient } from '@launchdarkly/jest/react-native';
|
|
46
53
|
import Welcome from './Welcome';
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
describe('Welcome component', () => {
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
// reset before each test case
|
|
58
|
+
resetLDMocks();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('evaluates a boolean flag', () => {
|
|
62
|
+
// arrange
|
|
63
|
+
// You can use camelCase, kebab-case, or snake_case keys
|
|
64
|
+
mockFlags({ 'my-boolean-flag': true });
|
|
65
|
+
|
|
66
|
+
// act
|
|
67
|
+
const { getByText } = render(<Welcome />);
|
|
68
|
+
|
|
69
|
+
// assert
|
|
70
|
+
expect(getByText('Flag value is true')).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('captures a track call', () => {
|
|
74
|
+
// arrange
|
|
75
|
+
mockFlags({ myBooleanFlag: true });
|
|
76
|
+
const client = getLDClient();
|
|
77
|
+
|
|
78
|
+
// act
|
|
79
|
+
const { getByTestId } = render(<Welcome />);
|
|
80
|
+
fireEvent.press(getByTestId('track-button'));
|
|
81
|
+
|
|
82
|
+
// assert: track gets called
|
|
83
|
+
expect(client.track).toHaveBeenCalledWith('event-name', { foo: 'bar' });
|
|
84
|
+
expect(client.track).toHaveBeenCalledTimes(1);
|
|
85
|
+
});
|
|
56
86
|
});
|
|
87
|
+
```
|
|
57
88
|
|
|
58
|
-
|
|
59
|
-
const client = getLDClient(); // mocked client from LD jest tooling
|
|
60
|
-
client.track('event-name', { foo: 'bar' });
|
|
61
|
-
expect(client.track).toHaveBeenCalledWith('event-name', { foo: 'bar' });
|
|
62
|
-
expect(client.track).toHaveBeenCalledTimes(1);
|
|
63
|
-
});
|
|
89
|
+
---
|
|
64
90
|
|
|
65
91
|
## Developing this package
|
|
66
92
|
|
|
@@ -71,6 +97,9 @@ yarn && yarn build && cd packages/tooling/jest
|
|
|
71
97
|
# run tests
|
|
72
98
|
yarn test
|
|
73
99
|
```
|
|
100
|
+
## Note
|
|
101
|
+
|
|
102
|
+
LaunchDarkly plans to support [test data sources](https://launchdarkly.com/docs/sdk/features/test-data-sources) for the React Native and other client-side SDKs in the future. Once this feature is avaliable, we will deprecate this package.
|
|
74
103
|
|
|
75
104
|
## Verifying SDK build provenance with the SLSA framework
|
|
76
105
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@launchdarkly/jest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Easily unit test LaunchDarkly feature flagged components with jest",
|
|
5
5
|
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/tooling/jest",
|
|
6
6
|
"repository": {
|