@applicaster/zapp-react-native-utils 13.0.0-alpha.8362430079 → 13.0.0-alpha.8432878190
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/README.md +0 -10
- package/appUtils/contextKeysManager/index.ts +2 -2
- package/appUtils/contextKeysManager/utils/index.ts +2 -1
- package/equalUtils/index.ts +10 -3
- package/focusManager/FocusManager.ts +11 -1
- package/numberUtils/index.ts +5 -7
- package/package.json +2 -2
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +7 -5
- package/reactHooks/autoscrolling/useTrackedView.ts +1 -12
- package/reactHooks/navigation/index.ts +7 -19
- package/reactHooks/navigation/useProfilerLogging.ts +15 -0
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +5 -0
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +1 -1
- package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
- package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
- package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
- package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
- package/reactUtils/createContext/__tests__/provider.test.js +4 -6
- package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
- package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
- package/testUtils/index.tsx +0 -10
package/README.md
CHANGED
|
@@ -376,16 +376,6 @@ useEffect(() => {
|
|
|
376
376
|
}, []);
|
|
377
377
|
```
|
|
378
378
|
|
|
379
|
-
### testUtils
|
|
380
|
-
|
|
381
|
-
`@applicaster/zapp-react-native-utils/testUtils`
|
|
382
|
-
|
|
383
|
-
- `testIDEquals: (testId: any) => boolean | { width: number, height: number }` - Function to be used in tandem with enzyme findWhere
|
|
384
|
-
|
|
385
|
-
```javascript
|
|
386
|
-
wrapper.findWhere(testIDEquals("text"));
|
|
387
|
-
```
|
|
388
|
-
|
|
389
379
|
### appUtils - contextKeysManager
|
|
390
380
|
|
|
391
381
|
`@applicaster/zapp-react-native-utils/appUtils/contextKeyManager`
|
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
|
|
17
17
|
export { StorageLevel };
|
|
18
18
|
|
|
19
|
-
type KeyNameObj = {
|
|
19
|
+
export type KeyNameObj = {
|
|
20
20
|
namespace: string;
|
|
21
21
|
key: string;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
type KeyName = string | KeyNameObj;
|
|
24
|
+
export type KeyName = string | KeyNameObj;
|
|
25
25
|
|
|
26
26
|
type ParsedKeyAndNamespace = {
|
|
27
27
|
namespace?: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { DEFAULT_NAMESPACE } from "../consts";
|
|
3
|
+
import { KeyName, KeyNameObj } from "../index";
|
|
3
4
|
|
|
4
5
|
const lastDotRegex = /\.([^.]+)$/;
|
|
5
6
|
const splitByLastDot = R.compose(R.init, R.split(lastDotRegex));
|
|
6
7
|
|
|
7
|
-
export function getNamespaceAndKey(namespacedKey) {
|
|
8
|
+
export function getNamespaceAndKey(namespacedKey: KeyName): KeyNameObj {
|
|
8
9
|
if (typeof namespacedKey !== "string") return namespacedKey;
|
|
9
10
|
|
|
10
11
|
const namespacedKeyProps = namespacedKey.includes(".")
|
package/equalUtils/index.ts
CHANGED
|
@@ -49,9 +49,16 @@ export const isEqual =
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (compareRemainingKeysBySameValue) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
53
|
+
|
|
54
|
+
const declaredKeys = new Set([
|
|
55
|
+
...byValue,
|
|
56
|
+
...byReference,
|
|
57
|
+
...byComparator.keys,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const undeclaredKeys = Array.from(allKeys).filter(
|
|
61
|
+
(key) => !declaredKeys.has(key)
|
|
55
62
|
);
|
|
56
63
|
|
|
57
64
|
const isRestKeysEqualAllBySameValue = undeclaredKeys.every((key) =>
|
|
@@ -250,7 +250,17 @@ class FocusManager {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
onDisableFocusChange = (id) => {
|
|
253
|
-
|
|
253
|
+
const isFocused = FocusManager.instance.isFocused(id);
|
|
254
|
+
|
|
255
|
+
const isDescendantFocused = (() => {
|
|
256
|
+
try {
|
|
257
|
+
return FocusManager.instance.isAnyDescendantFocused(id);
|
|
258
|
+
} catch (_e) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
})();
|
|
262
|
+
|
|
263
|
+
if (isFocused || isDescendantFocused) {
|
|
254
264
|
// Move focus to next one
|
|
255
265
|
const nextFocus = FocusManager.instance.focused?.props
|
|
256
266
|
?.nextFocusDown as string;
|
package/numberUtils/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { logger } from "@applicaster/zapp-react-native-utils/logger";
|
|
|
3
3
|
|
|
4
4
|
const numberUtilsLogger = logger?.addSubsystem("NumberUtils");
|
|
5
5
|
|
|
6
|
-
export const toNumber = (value:
|
|
6
|
+
export const toNumber = (value: any): number | undefined => {
|
|
7
7
|
if (R.isNil(value) || R.isEmpty(value)) {
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
@@ -17,12 +17,10 @@ export const toNumber = (value: unknown): number | undefined => {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const toNumberWithDefault = (
|
|
21
|
-
defaultValue
|
|
22
|
-
value: unknown
|
|
23
|
-
): number => toNumber(value) ?? defaultValue;
|
|
20
|
+
export const toNumberWithDefault = (defaultValue: number, value: any): number =>
|
|
21
|
+
toNumber(value) ?? defaultValue;
|
|
24
22
|
|
|
25
|
-
export const toNumberWithDefaultZero = (value:
|
|
23
|
+
export const toNumberWithDefaultZero = (value: any): number =>
|
|
26
24
|
toNumberWithDefault(0, value);
|
|
27
25
|
|
|
28
26
|
export const requireNumber = (obj, key: string) => {
|
|
@@ -41,7 +39,7 @@ export const requireNumber = (obj, key: string) => {
|
|
|
41
39
|
|
|
42
40
|
export const toFiniteNumberWithDefault = (
|
|
43
41
|
defaultValue: number,
|
|
44
|
-
value:
|
|
42
|
+
value: any
|
|
45
43
|
): number => {
|
|
46
44
|
const possibleNumber = toNumberWithDefault(defaultValue, value);
|
|
47
45
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.8432878190",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "13.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.8432878190",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -35,23 +35,25 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
|
35
35
|
const { useTrackedView } = require("../useTrackedView");
|
|
36
36
|
|
|
37
37
|
describe("useTrackCurrentAutoScrollingElement", () => {
|
|
38
|
-
it("should update position for selected component
|
|
38
|
+
it("should update position for selected component", async () => {
|
|
39
39
|
const { result } = renderHook(() => useTrackedView("123"), {
|
|
40
40
|
wrapper: Wrapper,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
// Fast-forward until all timers have been executed
|
|
44
|
+
jest.advanceTimersByTime(3000);
|
|
45
|
+
|
|
43
46
|
expect(result.current.inViewPort).toBe(false);
|
|
44
47
|
|
|
45
48
|
const mockRect = {
|
|
46
49
|
rect: { left: 1, right: 1, top: 1, bottom: 1 },
|
|
47
50
|
};
|
|
48
51
|
|
|
49
|
-
act(
|
|
50
|
-
|
|
52
|
+
act(() => {
|
|
53
|
+
result.current.onPositionUpdated(mockRect);
|
|
51
54
|
});
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
jest.runAllTimers();
|
|
56
|
+
jest.advanceTimersByTime(3000);
|
|
55
57
|
|
|
56
58
|
expect(result.current.inViewPort).toBe(true);
|
|
57
59
|
|
|
@@ -2,10 +2,6 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
2
2
|
import { useScreenTrackedViewPositionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext";
|
|
3
3
|
import { useDimensions } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
|
|
4
4
|
import { findTrackedView } from "./utils/findTrackedView";
|
|
5
|
-
import { isNil } from "ramda";
|
|
6
|
-
import { withTimeout } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
7
|
-
|
|
8
|
-
const TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT = 500; // ms
|
|
9
5
|
|
|
10
6
|
const getNormalizedRect = (rect, componentId, screenWidth, screenHeight) => {
|
|
11
7
|
if (!rect) {
|
|
@@ -41,16 +37,9 @@ export const useTrackedView = (componentId: string) => {
|
|
|
41
37
|
);
|
|
42
38
|
|
|
43
39
|
const onPositionUpdated = useCallback(
|
|
44
|
-
|
|
40
|
+
({ rect }) => {
|
|
45
41
|
const currentPosition = normalizedRect(componentId, rect);
|
|
46
42
|
|
|
47
|
-
// There is an issue on the native side where they are unable to guarantee
|
|
48
|
-
// that the order of onViewportLeave and onViewportEnter events is always correct.
|
|
49
|
-
// This workaround/hack delays the onViewportEnter event to ensure it is received last.
|
|
50
|
-
if (!isNil(currentPosition)) {
|
|
51
|
-
await withTimeout(TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
43
|
updateComponentsPositions(componentId, currentPosition as any);
|
|
55
44
|
|
|
56
45
|
setInViewPort(!!currentPosition);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BackHandler
|
|
1
|
+
import { useContext, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { BackHandler } from "react-native";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
useContentTypes,
|
|
@@ -31,6 +31,8 @@ export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
|
|
|
31
31
|
|
|
32
32
|
export { useIsScreenActive } from "./useIsScreenActive";
|
|
33
33
|
|
|
34
|
+
export { useProfilerLogging } from "./useProfilerLogging";
|
|
35
|
+
|
|
34
36
|
export {
|
|
35
37
|
useUniqueRouteSuffix,
|
|
36
38
|
useNavbarId,
|
|
@@ -121,10 +123,8 @@ export function isNavBarVisible(
|
|
|
121
123
|
return true;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
const { ProfilerBridge } = NativeModules;
|
|
125
|
-
|
|
126
126
|
export const useBackHandler = (cb: () => boolean) => {
|
|
127
|
-
|
|
127
|
+
useEffect(() => {
|
|
128
128
|
BackHandler.addEventListener("hardwareBackPress", cb);
|
|
129
129
|
|
|
130
130
|
return () => {
|
|
@@ -158,7 +158,7 @@ export const useZappHooksForEntry = (
|
|
|
158
158
|
setIsHooksExecutionInProgress,
|
|
159
159
|
setIsPresentingFullScreen,
|
|
160
160
|
setIsRunningInBackground,
|
|
161
|
-
}: HookModalContextT =
|
|
161
|
+
}: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
|
|
162
162
|
|
|
163
163
|
const {
|
|
164
164
|
appData: { layoutVersion },
|
|
@@ -256,22 +256,10 @@ export const useZappHooksForEntry = (
|
|
|
256
256
|
}, [entry.id]);
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
export const useProfilerLogging = () => {
|
|
260
|
-
const logTimestamp = (data: string) =>
|
|
261
|
-
InteractionManager.runAfterInteractions(() => {
|
|
262
|
-
if (ProfilerBridge && data) {
|
|
263
|
-
ProfilerBridge.updateTimer("navigation", data, Date.now());
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return logTimestamp;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
259
|
export const useRunIfLongPress = (
|
|
271
260
|
options = { timeout: LONG_KEY_PRESS_TIMEOUT }
|
|
272
261
|
) => {
|
|
273
|
-
const pressTimeout =
|
|
274
|
-
React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
262
|
+
const pressTimeout = useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
275
263
|
|
|
276
264
|
const resetTimeout = () => {
|
|
277
265
|
clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { InteractionManager, NativeModules } from "react-native";
|
|
3
|
+
|
|
4
|
+
const { ProfilerBridge } = NativeModules;
|
|
5
|
+
|
|
6
|
+
export const useProfilerLogging = () =>
|
|
7
|
+
useCallback(
|
|
8
|
+
(data: string) =>
|
|
9
|
+
InteractionManager.runAfterInteractions(() => {
|
|
10
|
+
if (ProfilerBridge && data) {
|
|
11
|
+
ProfilerBridge.updateTimer("navigation", data, Date.now());
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
@@ -93,6 +93,8 @@ export class TVSeekController
|
|
|
93
93
|
this.isPlayerInitiallyPaused = this.playerController.isPaused();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
log_debug(`handleStartSeek: seekType: ${seekType}, initiallyPaused: ${this.isPlayerInitiallyPaused}`);
|
|
97
|
+
|
|
96
98
|
this.clearLongPressThresholdTimeout();
|
|
97
99
|
this.clearSeekCompleteTimeout();
|
|
98
100
|
this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
|
|
@@ -117,6 +119,7 @@ export class TVSeekController
|
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
onSeekEnd = () => {
|
|
122
|
+
log_debug("onSeekEnd: Seek ended");
|
|
120
123
|
this.clearLongPressThresholdTimeout();
|
|
121
124
|
this.currentSeekController.onSeekEnd();
|
|
122
125
|
};
|
|
@@ -174,6 +177,8 @@ export class TVSeekController
|
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
179
|
|
|
180
|
+
log_debug(`handleDelayedSeek: currentPos: ${currentPos} targetPos:${targetPos}, initiallyPaused: ${this.isPlayerInitiallyPaused}`);
|
|
181
|
+
|
|
177
182
|
this.delayedSeekPosition = targetPos;
|
|
178
183
|
this.delayedSeekProgressSubject.next(targetPos);
|
|
179
184
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
|
|
3
|
+
exports[`reactUtils helpers addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
|
|
4
4
|
<View>
|
|
5
5
|
<Text>
|
|
6
6
|
I'm a class component
|
|
@@ -8,7 +8,7 @@ exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`]
|
|
|
8
8
|
</View>
|
|
9
9
|
`;
|
|
10
10
|
|
|
11
|
-
exports[`attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
|
|
11
|
+
exports[`reactUtils helpers attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
|
|
12
12
|
<View>
|
|
13
13
|
<Text>
|
|
14
14
|
I'm a class component
|
|
@@ -16,6 +16,18 @@ exports[`attachMethodToPrototype attaches a lifecycle method to the component's
|
|
|
16
16
|
</View>
|
|
17
17
|
`;
|
|
18
18
|
|
|
19
|
-
exports[`attachMethodToPrototype preserves any existing lifecycle method 1`] =
|
|
19
|
+
exports[`reactUtils helpers attachMethodToPrototype preserves any existing lifecycle method 1`] = `
|
|
20
|
+
<View>
|
|
21
|
+
<Text>
|
|
22
|
+
I'm a stateless component
|
|
23
|
+
</Text>
|
|
24
|
+
</View>
|
|
25
|
+
`;
|
|
20
26
|
|
|
21
|
-
exports[`wrapInClass wraps the stateless component in a class 1`] =
|
|
27
|
+
exports[`reactUtils helpers wrapInClass wraps the stateless component in a class 1`] = `
|
|
28
|
+
<View>
|
|
29
|
+
<Text>
|
|
30
|
+
I'm a stateless component
|
|
31
|
+
</Text>
|
|
32
|
+
</View>
|
|
33
|
+
`;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
4
3
|
|
|
5
4
|
import {
|
|
6
5
|
isClassComponent,
|
|
@@ -20,98 +19,100 @@ import {
|
|
|
20
19
|
} from "./fixtures";
|
|
21
20
|
|
|
22
21
|
describe("reactUtils helpers", () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
describe("isNilOrEmpty", () => {
|
|
23
|
+
it("should return correct output", () => {
|
|
24
|
+
expect(isNilOrEmpty).toBeDefined();
|
|
25
|
+
expect(isNilOrEmpty(null)).toBeTruthy();
|
|
26
|
+
expect(isNilOrEmpty(undefined)).toBeTruthy();
|
|
27
|
+
expect(isNilOrEmpty("")).toBeTruthy();
|
|
28
|
+
expect(isNilOrEmpty([])).toBeTruthy();
|
|
29
|
+
});
|
|
29
30
|
});
|
|
30
|
-
});
|
|
31
31
|
|
|
32
|
-
describe("isClassComponent", () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
describe("isClassComponent", () => {
|
|
33
|
+
it("returns true if the component is a class component", () => {
|
|
34
|
+
expect(isClassComponent(ClassComponent)).toBe(true);
|
|
35
|
+
});
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
it("returns false otherwise", () => {
|
|
38
|
+
expect(isClassComponent(StatelessComponent)).toBe(false);
|
|
39
|
+
});
|
|
39
40
|
});
|
|
40
|
-
});
|
|
41
41
|
|
|
42
|
-
describe("attachMethodToPrototype", () => {
|
|
43
|
-
|
|
42
|
+
describe("attachMethodToPrototype", () => {
|
|
43
|
+
const initialWrapper = render(<ClassComponent />);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
COMPONENT_DID_MOUNT_METHOD
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
componentDidMount.mockClear();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("attaches a lifecycle method to the component's prototype", () => {
|
|
54
|
-
const NewComponent = attachMethodToPrototype(ClassComponent)(
|
|
55
|
-
componentDidMount,
|
|
45
|
+
expect(initialWrapper.toJSON()).not.toHaveProperty(
|
|
56
46
|
COMPONENT_DID_MOUNT_METHOD
|
|
57
47
|
);
|
|
58
48
|
|
|
59
|
-
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
componentDidMount.mockClear();
|
|
51
|
+
});
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
it("attaches a lifecycle method to the component's prototype", () => {
|
|
54
|
+
const NewComponent = attachMethodToPrototype(ClassComponent)(
|
|
55
|
+
componentDidMount,
|
|
56
|
+
COMPONENT_DID_MOUNT_METHOD
|
|
57
|
+
);
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
|
|
68
|
-
componentDidMount,
|
|
69
|
-
COMPONENT_DID_MOUNT_METHOD
|
|
70
|
-
);
|
|
59
|
+
const wrapper = render(<NewComponent />);
|
|
71
60
|
|
|
72
|
-
|
|
61
|
+
expect(wrapper.toJSON(wrapper)).toMatchSnapshot();
|
|
62
|
+
expect(new NewComponent()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
|
|
63
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
64
|
+
});
|
|
73
65
|
|
|
74
|
-
|
|
66
|
+
it("preserves any existing lifecycle method", () => {
|
|
67
|
+
const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
|
|
68
|
+
componentDidMount,
|
|
69
|
+
COMPONENT_DID_MOUNT_METHOD
|
|
70
|
+
);
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
expect(componentDidMount).toHaveBeenCalled();
|
|
78
|
-
expect(existingMethod).toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
72
|
+
expect(componentDidMount).not.toHaveBeenCalled();
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
let NewComponent;
|
|
84
|
-
let wrapper;
|
|
74
|
+
const wrapper = render(<NewComponent />);
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
77
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
78
|
+
expect(existingMethod).toHaveBeenCalled();
|
|
79
|
+
});
|
|
89
80
|
});
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
});
|
|
82
|
+
describe("wrapInClass", () => {
|
|
83
|
+
let NewComponent;
|
|
84
|
+
let wrapper;
|
|
96
85
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
NewComponent = wrapInClass(StatelessComponent);
|
|
88
|
+
wrapper = render(<NewComponent />);
|
|
89
|
+
});
|
|
100
90
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
it("wraps the stateless component in a class", () => {
|
|
92
|
+
expect(isClassComponent(NewComponent)).toBe(true);
|
|
93
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
94
|
+
});
|
|
104
95
|
});
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
97
|
+
describe("addLifeCycleMethods", () => {
|
|
98
|
+
let NewComponent;
|
|
99
|
+
let wrapper;
|
|
109
100
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
NewComponent = addLifeCycleMethods({ componentDidMount })(ClassComponent);
|
|
103
|
+
wrapper = render(<NewComponent />);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
componentDidMount.mockClear();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("attaches the lifecycle method to the component", () => {
|
|
111
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
it("adds the lifecycle method to the component", () => {
|
|
115
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
116
|
+
});
|
|
116
117
|
});
|
|
117
118
|
});
|
|
@@ -1,59 +1,27 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
|
|
3
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"bar": "bar",
|
|
6
6
|
"foo": "foo",
|
|
7
7
|
}
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
11
|
-
{
|
|
12
|
-
"bar": "bar",
|
|
13
|
-
"foo": "invalid foo",
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
18
|
-
{
|
|
19
|
-
"bar": "invalid bar",
|
|
20
|
-
"foo": "invalid foo",
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[Function],
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
[Function],
|
|
31
|
-
],
|
|
32
|
-
]
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 1`] = `
|
|
10
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
36
11
|
{
|
|
37
12
|
"bar": "bar",
|
|
38
13
|
"foo": "foo",
|
|
39
14
|
}
|
|
40
15
|
`;
|
|
41
16
|
|
|
42
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called
|
|
17
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
43
18
|
{
|
|
44
19
|
"bar": "bar",
|
|
45
|
-
"foo": "
|
|
46
|
-
}
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 3`] = `
|
|
50
|
-
{
|
|
51
|
-
"bar": "new bar",
|
|
52
|
-
"foo": "new foo",
|
|
20
|
+
"foo": "foo",
|
|
53
21
|
}
|
|
54
22
|
`;
|
|
55
23
|
|
|
56
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called
|
|
24
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
57
25
|
[
|
|
58
26
|
[
|
|
59
27
|
[Function],
|
|
@@ -64,43 +32,9 @@ exports[`createContextSetters when state validator is provided calls setState wh
|
|
|
64
32
|
]
|
|
65
33
|
`;
|
|
66
34
|
|
|
67
|
-
exports[`createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
35
|
+
exports[`helpers createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
68
36
|
{
|
|
69
37
|
"bar": "bar",
|
|
70
38
|
"foo": "new foo",
|
|
71
39
|
}
|
|
72
40
|
`;
|
|
73
|
-
|
|
74
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 1`] = `
|
|
75
|
-
{
|
|
76
|
-
"bar": "bar",
|
|
77
|
-
"foo": "foo",
|
|
78
|
-
}
|
|
79
|
-
`;
|
|
80
|
-
|
|
81
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 2`] = `
|
|
82
|
-
{
|
|
83
|
-
"bar": "bar",
|
|
84
|
-
"foo": "foo",
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 3`] = `
|
|
89
|
-
{
|
|
90
|
-
"bar": "bar",
|
|
91
|
-
"foo": "foo",
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
|
|
95
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 4`] = `
|
|
96
|
-
[
|
|
97
|
-
[
|
|
98
|
-
"trying to invoke setFoo with invalid foo - but it was rejected by the state validator
|
|
99
|
-
skipping context update",
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
"trying to invoke setBar with invalid bar - but it was rejected by the state validator
|
|
103
|
-
skipping context update",
|
|
104
|
-
],
|
|
105
|
-
]
|
|
106
|
-
`;
|
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`createProvider creates a context Provider component 1`] = `
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"context": "initialValue",
|
|
8
|
-
"otherContext": "otherValue",
|
|
9
|
-
"setContext": [Function],
|
|
10
|
-
"setOtherContext": [Function],
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
>
|
|
14
|
-
<MockChild
|
|
15
|
-
context="context"
|
|
16
|
-
/>
|
|
17
|
-
</mockConstructor>
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
exports[`createProvider creates a context Provider component 2`] = `
|
|
21
|
-
{
|
|
22
|
-
"children": <MockChild
|
|
23
|
-
context="context"
|
|
24
|
-
/>,
|
|
25
|
-
"value": {
|
|
26
|
-
"context": "initialValue",
|
|
27
|
-
"otherContext": "otherValue",
|
|
28
|
-
"setContext": [Function],
|
|
29
|
-
"setOtherContext": [Function],
|
|
30
|
-
},
|
|
31
|
-
}
|
|
4
|
+
<View>
|
|
5
|
+
context
|
|
6
|
+
</View>
|
|
32
7
|
`;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { shallow } from "enzyme";
|
|
3
2
|
import { View, Text } from "react-native";
|
|
4
3
|
|
|
4
|
+
import { NOOP, getSetterName, createContextSetters } from "../helpers";
|
|
5
|
+
|
|
5
6
|
function stateValidator({ property, value }) {
|
|
6
7
|
return (
|
|
7
8
|
(property === "foo" && value === "new foo") ||
|
|
@@ -9,150 +10,135 @@ function stateValidator({ property, value }) {
|
|
|
9
10
|
);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
reactUtilsLogger: {
|
|
18
|
-
addSubsystem: jest.fn(() => mockLogger),
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
const { NOOP, getSetterName, createContextSetters } = require("../helpers");
|
|
23
|
-
|
|
24
|
-
describe("NOOP", () => {
|
|
25
|
-
it("does nothing", () => {
|
|
26
|
-
expect(NOOP()).toBeUndefined();
|
|
13
|
+
describe("helpers", () => {
|
|
14
|
+
describe("NOOP", () => {
|
|
15
|
+
it("does nothing", () => {
|
|
16
|
+
expect(NOOP()).toBeUndefined();
|
|
17
|
+
});
|
|
27
18
|
});
|
|
28
|
-
});
|
|
29
19
|
|
|
30
|
-
describe("getSetterName", () => {
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
describe("getSetterName", () => {
|
|
21
|
+
it("returns a setter name for the given property name", () => {
|
|
22
|
+
expect(getSetterName("fooBar")).toBe("setFooBar");
|
|
23
|
+
});
|
|
33
24
|
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe("createContextSetters", () => {
|
|
37
|
-
describe("when state validator is provided", () => {
|
|
38
|
-
class Component extends React.Component {
|
|
39
|
-
constructor(props) {
|
|
40
|
-
super(props);
|
|
41
|
-
this.state = { foo: "foo", bar: "bar" };
|
|
42
|
-
createContextSetters(["foo", "bar"], this, { stateValidator });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resetInitialState() {
|
|
46
|
-
this.setState({ foo: "foo", bar: "bar" });
|
|
47
|
-
}
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
26
|
+
describe("createContextSetters", () => {
|
|
27
|
+
describe("when state validator is provided", () => {
|
|
28
|
+
class ClassComponent {
|
|
29
|
+
constructor() {
|
|
30
|
+
this._state = { foo: "foo", bar: "bar" };
|
|
31
|
+
createContextSetters(["foo", "bar"], this, { stateValidator });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setState(newState) {
|
|
35
|
+
if (typeof newState === "function") {
|
|
36
|
+
this.state = newState(this.state);
|
|
37
|
+
} else {
|
|
38
|
+
this.state = { ...this.state, ...newState };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
set state(val) {
|
|
43
|
+
this._state = val;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get state() {
|
|
47
|
+
return this._state;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getState() {
|
|
51
|
+
return this._state;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
resetInitialState() {
|
|
55
|
+
this.setState({ foo: "foo", bar: "bar" });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
render() {
|
|
59
|
+
return <View testID="test-view">{JSON.stringify(this.state)}</View>;
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
|
-
}
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
const instance = wrapper.instance();
|
|
60
|
-
const setStateSpy = jest.spyOn(instance, "setState");
|
|
63
|
+
let instance;
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
mockLogger.warning.mockClear();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("adds all properties and setters to the component", () => {
|
|
69
|
-
expect(instance).toHaveProperty("setFoo");
|
|
70
|
-
expect(instance.setFoo).toBeFunction();
|
|
71
|
-
expect(instance).toHaveProperty("setBar");
|
|
72
|
-
expect(instance.setBar).toBeFunction();
|
|
73
|
-
});
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
instance = new ClassComponent();
|
|
67
|
+
});
|
|
74
68
|
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
it("calls setState when the setters are called & the validator passes", () => {
|
|
70
|
+
expect(instance.state.foo).toEqual("foo");
|
|
71
|
+
expect(instance.state.bar).toEqual("bar");
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
instance.setBar("new bar");
|
|
82
|
-
expect(instance.state).toMatchSnapshot();
|
|
83
|
-
|
|
84
|
-
expect(setStateSpy).toHaveBeenCalledTimes(2);
|
|
85
|
-
expect(setStateSpy.mock.calls).toMatchSnapshot();
|
|
86
|
-
expect(mockLogger.warning).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
73
|
+
instance.setFoo("new foo");
|
|
74
|
+
expect(instance.state.foo).toEqual("new foo");
|
|
88
75
|
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
instance.setBar("new bar");
|
|
77
|
+
expect(instance.state.bar).toEqual("new bar");
|
|
78
|
+
});
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
it("skips the update if the state validator doesn't pass", () => {
|
|
81
|
+
expect(instance.state.foo).toEqual("foo");
|
|
82
|
+
expect(instance.state.bar).toEqual("bar");
|
|
94
83
|
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
instance.setFoo("invalid foo");
|
|
85
|
+
expect(instance.state.foo).toEqual("foo");
|
|
97
86
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
87
|
+
instance.setBar("invalid bar");
|
|
88
|
+
expect(instance.state.bar).toEqual("bar");
|
|
89
|
+
});
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
it("skips the update if the new value is the same as the previous one", () => {
|
|
92
|
+
instance.setFoo("new foo");
|
|
93
|
+
instance.setFoo("new foo");
|
|
94
|
+
expect(instance.state).toMatchSnapshot();
|
|
95
|
+
});
|
|
108
96
|
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("when no state validator is provided", () => {
|
|
112
|
-
class Component extends React.Component {
|
|
113
|
-
constructor(props) {
|
|
114
|
-
super(props);
|
|
115
|
-
this.state = { foo: "foo", bar: "bar" };
|
|
116
|
-
createContextSetters(["foo", "bar"], this);
|
|
117
|
-
}
|
|
118
97
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
98
|
+
describe("when no state validator is provided", () => {
|
|
99
|
+
class Component extends React.Component {
|
|
100
|
+
constructor(props) {
|
|
101
|
+
super(props);
|
|
102
|
+
this.state = { foo: "foo", bar: "bar" };
|
|
103
|
+
createContextSetters(["foo", "bar"], this);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
render() {
|
|
107
|
+
return (
|
|
108
|
+
<View>
|
|
109
|
+
<Text>I am a component </Text>
|
|
110
|
+
</View>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
125
113
|
}
|
|
126
|
-
}
|
|
127
114
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
115
|
+
// const wrapper = new Component();
|
|
116
|
+
const instance = new Component();
|
|
117
|
+
const setStateSpy = jest.spyOn(instance, "setState");
|
|
131
118
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
119
|
+
afterEach(() => {
|
|
120
|
+
setStateSpy.mockClear();
|
|
121
|
+
});
|
|
136
122
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
it("adds all properties and setters to the component", () => {
|
|
124
|
+
expect(instance).toHaveProperty("setFoo");
|
|
125
|
+
expect(instance.setFoo).toBeFunction();
|
|
126
|
+
expect(instance).toHaveProperty("setBar");
|
|
127
|
+
expect(instance.setBar).toBeFunction();
|
|
128
|
+
});
|
|
143
129
|
|
|
144
|
-
|
|
145
|
-
|
|
130
|
+
it("calls setState when the setters are called, no matter what the value is", () => {
|
|
131
|
+
expect(instance.state).toMatchSnapshot();
|
|
146
132
|
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
instance.setFoo("invalid foo");
|
|
134
|
+
expect(instance.state).toMatchSnapshot();
|
|
149
135
|
|
|
150
|
-
|
|
151
|
-
|
|
136
|
+
instance.setBar("invalid bar");
|
|
137
|
+
expect(instance.state).toMatchSnapshot();
|
|
152
138
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
expect(setStateSpy).toHaveBeenCalledTimes(2);
|
|
140
|
+
expect(setStateSpy.mock.calls).toMatchSnapshot();
|
|
141
|
+
});
|
|
156
142
|
});
|
|
157
143
|
});
|
|
158
144
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createProvider } from "../provider";
|
|
@@ -29,14 +29,12 @@ describe("createProvider", () => {
|
|
|
29
29
|
it("creates a context Provider component", () => {
|
|
30
30
|
const MockChild = (props) => <View>{props.context}</View>;
|
|
31
31
|
|
|
32
|
-
const wrapper =
|
|
32
|
+
const wrapper = render(
|
|
33
33
|
<Provider>
|
|
34
34
|
<MockChild context={"context"} />
|
|
35
35
|
</Provider>
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
expect(
|
|
39
|
-
|
|
40
|
-
expect(wrapper.find(ReactContext.Provider).props()).toMatchSnapshot();
|
|
38
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
41
39
|
});
|
|
42
40
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createWithConsumerDecorator } from "../withConsumer";
|
|
@@ -11,21 +11,21 @@ describe("createConsumer", () => {
|
|
|
11
11
|
const { Consumer } = ReactContext;
|
|
12
12
|
const withConsumer = createWithConsumerDecorator(Consumer);
|
|
13
13
|
|
|
14
|
-
it("returns a function", () => {
|
|
15
|
-
expect(withConsumer).toBeFunction();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
14
|
it("creates a context consumer function", () => {
|
|
19
|
-
|
|
20
|
-
const DecoratedChild = withConsumer(Child);
|
|
15
|
+
expect(withConsumer).toBeFunction();
|
|
21
16
|
const newContextValue = "newValue";
|
|
22
17
|
|
|
23
|
-
const
|
|
18
|
+
const Child = (props) => {
|
|
19
|
+
props.setContext(newContextValue);
|
|
20
|
+
|
|
21
|
+
return <View>{props.context}</View>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DecoratedChild = withConsumer(Child);
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const wrapper = render(<DecoratedChild />);
|
|
26
27
|
|
|
27
|
-
expect(
|
|
28
|
-
childWrapper.props().setContext(newContextValue);
|
|
28
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
29
29
|
|
|
30
30
|
expect(mockContextData.setContext).toHaveBeenCalledWith(newContextValue);
|
|
31
31
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View, Text } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createWithProviderDecorator } from "../withProvider";
|
|
@@ -19,8 +19,8 @@ describe("withProvider", () => {
|
|
|
19
19
|
|
|
20
20
|
const DecoratedComponent = withProvider(Component);
|
|
21
21
|
|
|
22
|
-
const wrapper =
|
|
22
|
+
const wrapper = render(<DecoratedComponent />);
|
|
23
23
|
|
|
24
|
-
expect(
|
|
24
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
25
25
|
});
|
|
26
26
|
});
|
package/testUtils/index.tsx
CHANGED
|
@@ -15,16 +15,6 @@ import { ThemeContext } from "../theme";
|
|
|
15
15
|
|
|
16
16
|
export { getByTestId } from "./getByTestId";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
20
|
-
* Example:
|
|
21
|
-
* wrapper.findWhere(testIDEquals('yourID'))
|
|
22
|
-
* @param {*} testId
|
|
23
|
-
* @return boolean
|
|
24
|
-
*/
|
|
25
|
-
export const testIDEquals = (testId: any): boolean =>
|
|
26
|
-
R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
|
|
27
|
-
|
|
28
18
|
/** Helper function for react-test-renderer, accepts type and renderer
|
|
29
19
|
* * @param {*} type React Component type instance or name of component
|
|
30
20
|
* * @param {*} renderer renderer instance
|