You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/tooling/jest/README.md
+59-30Lines changed: 59 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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
-
> **Easily unit test LaunchDarkly applications with jest**:clap:
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
-
```shell
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
-
## Quickstart
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
-
// Welcome.test.tsx
43
+
-`getLDClient()`: Returns a jest mock of the [LDClient](https://launchdarkly.github.io/js-client-sdk/interfaces/_launchdarkly_js_client_sdk_.ldclient.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
importReactfrom'react';
40
-
import { render } from '@testing-library/react-native';
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
0 commit comments