Skip to content

Commit 6ffacc3

Browse files
authored
chore(docs): update jest README with testing examples and removed react setup instructions that are not currently available. (#889)
1 parent e70e484 commit 6ffacc3

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

packages/tooling/jest/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,39 @@ Then in `jest.config.js` add `@launchdarkly/jest/{framework}` to setupFiles:
2828
```js
2929
// jest.config.js
3030
module.exports = {
31-
// for react
32-
setupFiles: ['@launchdarkly/jest/react'],
33-
3431
// for react-native
3532
setupFiles: ['@launchdarkly/jest/react-native'],
3633
};
3734
```
3835

3936
## Quickstart
4037

41-
TODO:
38+
// Welcome.test.tsx
39+
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';
46+
import Welcome from './Welcome';
47+
48+
afterEach(() => {
49+
resetLDMocks();
50+
});
51+
52+
test('evaluates a boolean flag', () => {
53+
mockFlags({ 'my-boolean-flag': true });
54+
const { getByText } = render(<Welcome />);
55+
expect(getByText('Flag value is true')).toBeTruthy();
56+
});
57+
58+
test('captures a track call', () => {
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+
});
4264

4365
## Developing this package
4466

0 commit comments

Comments
 (0)