Skip to content

Commit aee09c8

Browse files
professorice“Menelikkinyoklion
authored
feat: Implement jest mocks for react-native. (#535)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** Provide links to any issues in this repository or elsewhere relating to this pull request. **Describe the solution you've provided** Provide a clear and concise description of what you expect to happen. **Describe alternatives you've considered** Provide a clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context about the pull request here. --------- Co-authored-by: “Menelik <“[email protected]”> Co-authored-by: Ryan Lamb <[email protected]>
1 parent 008dcf0 commit aee09c8

24 files changed

+456
-10
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
transform: { '^.+\\.ts?$': 'ts-jest' },
33
testMatch: ['**/__tests__/**/*test.ts?(x)'],
4-
testEnvironment: 'node',
4+
testEnvironment: 'jsdom',
55
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
66
collectCoverageFrom: [
77
'packages/sdk/server-node/src/**/*.ts',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"packages/store/node-server-sdk-dynamodb",
2323
"packages/telemetry/node-server-sdk-otel",
2424
"packages/tooling/jest",
25+
"packages/tooling/jest/example/react-native-example",
2526
"packages/sdk/browser",
2627
"packages/sdk/browser/contract-tests/entity",
2728
"packages/sdk/browser/contract-tests/adapter"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2+
3+
# dependencies
4+
node_modules/
5+
6+
# Expo
7+
.expo/
8+
dist/
9+
web-build/
10+
11+
# Native
12+
*.orig.*
13+
*.jks
14+
*.p8
15+
*.p12
16+
*.key
17+
*.mobileprovision
18+
19+
# Metro
20+
.metro-health-check*
21+
22+
# debug
23+
npm-debug.*
24+
yarn-debug.*
25+
yarn-error.*
26+
27+
# macOS
28+
.DS_Store
29+
*.pem
30+
31+
# local env files
32+
.env*.local
33+
34+
# typescript
35+
*.tsbuildinfo
36+
37+
# vscode
38+
.vscode
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { StyleSheet } from 'react-native';
2+
import {
3+
AutoEnvAttributes,
4+
LDProvider,
5+
ReactNativeLDClient,
6+
LDOptions,
7+
} from '@launchdarkly/react-native-client-sdk';
8+
import Welcome from './src/welcome';
9+
10+
const options: LDOptions = {
11+
debug: true,
12+
}
13+
//TODO Set MOBILE_KEY in .env file to a mobile key in your project/environment.
14+
const MOBILE_KEY = 'YOUR_MOBILE_KEY';
15+
const featureClient = new ReactNativeLDClient(MOBILE_KEY, AutoEnvAttributes.Enabled, options);
16+
17+
const userContext = { kind: 'user', key: '', anonymous: true };
18+
19+
export default function App() {
20+
featureClient.identify(userContext).catch((e: any) => console.log(e));
21+
22+
return (
23+
<LDProvider client={featureClient}>
24+
<Welcome />
25+
</LDProvider>
26+
);
27+
}
28+
29+
const styles = StyleSheet.create({
30+
container: {
31+
flex: 1,
32+
backgroundColor: '#fff',
33+
alignItems: 'center',
34+
justifyContent: 'center',
35+
},
36+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"expo": {
3+
"name": "react-native-jest-example",
4+
"slug": "react-native-jest-example",
5+
"version": "0.0.1",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"userInterfaceStyle": "light",
9+
"splash": {
10+
"image": "./assets/splash.png",
11+
"resizeMode": "contain",
12+
"backgroundColor": "#ffffff"
13+
},
14+
"ios": {
15+
"supportsTablet": true,
16+
"bundleIdentifier": "com.anonymous.reactnativejestexample"
17+
},
18+
"android": {
19+
"adaptiveIcon": {
20+
"foregroundImage": "./assets/adaptive-icon.png",
21+
"backgroundColor": "#ffffff"
22+
},
23+
"package": "com.anonymous.reactnativejestexample"
24+
},
25+
"web": {
26+
"favicon": "./assets/favicon.png"
27+
}
28+
}
29+
}
17.1 KB
Loading
1.43 KB
Loading
21.9 KB
Loading
46.2 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo', '@babel/preset-typescript'],
5+
6+
};
7+
};

0 commit comments

Comments
 (0)