Skip to content

Commit 641c12c

Browse files
committed
chore: upgrade react native testing library to v7
1 parent 8856df1 commit 641c12c

File tree

10 files changed

+33448
-14098
lines changed

10 files changed

+33448
-14098
lines changed

ios/Podfile.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,19 @@ PODS:
221221
- React-cxxreact (= 0.61.5)
222222
- React-jsi (= 0.61.5)
223223
- ReactCommon/jscallinvoker (= 0.61.5)
224-
- RNBootSplash (2.1.0):
224+
- RNBootSplash (2.2.8):
225+
- React-Core
226+
- RNCMaskedView (0.1.11):
225227
- React
226-
- RNCMaskedView (0.1.7):
227-
- React
228-
- RNGestureHandler (1.6.1):
229-
- React
230-
- RNLocalize (1.4.0):
231-
- React
232-
- RNReanimated (1.7.1):
233-
- React
234-
- RNScreens (2.4.0):
235-
- React
236-
- RNSVG (12.0.3):
228+
- RNGestureHandler (1.10.3):
229+
- React-Core
230+
- RNLocalize (1.4.3):
231+
- React-Core
232+
- RNReanimated (1.13.3):
233+
- React-Core
234+
- RNScreens (2.18.1):
235+
- React-Core
236+
- RNSVG (12.1.1):
237237
- React
238238
- Yoga (1.14.0)
239239

@@ -378,15 +378,15 @@ SPEC CHECKSUMS:
378378
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
379379
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
380380
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
381-
RNBootSplash: fbf76a4bf1c03e9acd1dd08ce064847f26d6d8bf
382-
RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814
383-
RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38
384-
RNLocalize: b6df30cc25ae736d37874f9bce13351db2f56796
385-
RNReanimated: 4e102df74a9674fa943e05f97f3362b6e44d0b48
386-
RNScreens: b5c0e1b2b04512919e78bd3898e144a157ce2363
387-
RNSVG: 7e16ddfc6e00d5aa69c9eb83e699bcce5dcb85d4
381+
RNBootSplash: 14d30c2e1de7247d334540cb2c2d7f3c2acc6150
382+
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
383+
RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211
384+
RNLocalize: 7c7aeda16c01db7a0918981c14875c0a53be9b79
385+
RNReanimated: 514a11da3a2bcc6c3dfd9de32b38e2b9bf101926
386+
RNScreens: f7ad633b2e0190b77b6a7aab7f914fad6f198d8d
387+
RNSVG: 551acb6562324b1d52a4e0758f7ca0ec234e278f
388388
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b
389389

390390
PODFILE CHECKSUM: 6d232769a3df22ec242f559aad72d785e04186ad
391391

392-
COCOAPODS: 1.9.3
392+
COCOAPODS: 1.10.0

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = compose(
1414
...config,
1515
moduleNameMapper: {
1616
...config.moduleNameMapper,
17-
'\\.svg': '<rootDir>/__mocks__/SvgMock.js',
17+
'\\.svg': '<rootDir>/__mocks__/MockSvg.js',
1818
},
1919
coveragePathIgnorePatterns: [
2020
...config.coveragePathIgnorePatterns,

package-lock.json

Lines changed: 33374 additions & 14049 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@react-navigation/native": "^5.0.9",
4747
"@react-navigation/stack": "^5.1.1",
4848
"hoist-non-react-statics": "^3.3.2",
49-
"react": "^16.9.0",
49+
"react": "16.9.0",
5050
"react-intl": "^4.5.0",
5151
"react-native": "0.61.5",
5252
"react-native-bootsplash": "^2.1.0",
@@ -67,23 +67,22 @@
6767
"@moxy/eslint-config-react": "^12.3.0",
6868
"@moxy/eslint-config-react-native": "^12.3.1",
6969
"@moxy/eslint-config-react-native-a11y": "^12.3.1",
70-
"@moxy/jest-config-base": "^5.0.0",
71-
"@moxy/jest-config-react-native": "^5.0.0",
72-
"@moxy/jest-config-testing-library": "^5.1.0",
73-
"@testing-library/react-native": "^5.0.3",
70+
"@moxy/jest-config-base": "^6.0.0",
71+
"@moxy/jest-config-react-native": "^6.0.0",
72+
"@moxy/jest-config-testing-library": "^6.0.0",
73+
"@testing-library/react-native": "^7.0.0",
7474
"babel-plugin-transform-remove-console": "^6.9.4",
7575
"commitlint": "^8.0.0",
7676
"eslint": "^6.8.0",
7777
"full-icu": "^1.3.1",
7878
"husky": "^4.2.0",
7979
"identity-obj-proxy": "^3.0.0",
80-
"jest": "^25.1.0",
80+
"jest": "^26.0.0",
8181
"lint-staged": "^10.0.2",
8282
"metro-react-native-babel-preset": "^0.59.0",
8383
"patch-package": "^6.2.2",
84-
"react-dom": "^16.13.1",
8584
"react-native-svg-transformer": "^0.14.3",
86-
"react-test-renderer": "^16.9.0",
85+
"react-test-renderer": "16.9.0",
8786
"rimraf": "^3.0.2",
8887
"source-map-cli": "^1.0.0",
8988
"standard-version": "^7.1.0"

src/navigation/root/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import * as React from 'react';
33
export const navigationRef = React.createRef();
44

55
export function navigate(name, params) {
6-
navigationRef.current?.navigate(name, params);
6+
/* eslint-disable-next-line babel/no-unused-expressions */
7+
navigationRef.current?.navigate(name, params);
78
}

src/shared/modules/react-native-button/Button.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
import React from 'react';
2+
import { TouchableHighlight, TouchableOpacity } from 'react-native';
23
import { fireEvent, render } from '@testing-library/react-native';
34
import Button from './Button';
45

56
it('should render a TouchableHighlight when no type is supplied', () => {
6-
const { getByLabelText } = render(
7+
const { UNSAFE_getByType: getByType } = render(
78
<Button
89
accessibilityLabel="button"
910
title="button"
1011
onPress={ () => null } />,
1112
);
1213

13-
const pressable = getByLabelText('button');
14+
const touchableHighlight = getByType(TouchableHighlight);
1415

15-
expect(pressable.type).toBe('TouchableHighlight');
16+
expect(touchableHighlight).toBeDefined();
1617
});
1718

1819
it('should render a TouchableOpacity when type is opacity', () => {
19-
const { getByLabelText } = render(
20+
const { UNSAFE_getByType: getByType } = render(
2021
<Button
2122
accessibilityLabel="button"
2223
title="button"
2324
onPress={ () => null }
2425
type="opacity" />,
2526
);
2627

27-
const pressable = getByLabelText('button');
28+
const touchableOpacity = getByType(TouchableOpacity);
2829

29-
expect(pressable.type).toBe('TouchableOpacity');
30+
expect(touchableOpacity).toBeDefined();
3031
});
3132

3233
it('should render title', () => {

src/shared/modules/react-native-locale/LocaleProvider.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const ReactNativeLocaleProvider = ({
3232
locales,
3333
initialLocaleId,
3434
onLocaleChange,
35+
textComponent,
3536
}) => {
3637
const intlCache = useRef(createIntlCache());
3738
const [currentLocale, setCurrentLocale] = useState(getInitialLocale(locales, locales[0], initialLocaleId));
@@ -46,6 +47,7 @@ const ReactNativeLocaleProvider = ({
4647
setCurrentLocale(nextLocale);
4748

4849
if (localeId !== currentLocale.id) {
50+
/* eslint-disable-next-line babel/no-unused-expressions */
4951
onLocaleChange?.(nextLocale.id);
5052
}
5153
}, [setCurrentLocale, locales, onLocaleChange, currentLocale]);
@@ -54,6 +56,7 @@ const ReactNativeLocaleProvider = ({
5456
const intl = createIntl({
5557
locale: currentLocale.id,
5658
messages: currentLocale.messages,
59+
textComponent,
5760
}, intlCache);
5861

5962
return {
@@ -63,7 +66,7 @@ const ReactNativeLocaleProvider = ({
6366
id: currentLocale.id,
6467
changeLocale: handleLocaleChange,
6568
};
66-
}, [handleLocaleChange, currentLocale, locales]);
69+
}, [handleLocaleChange, currentLocale, locales, textComponent]);
6770

6871
useEffect(() => {
6972
const locale = findLocaleById(locales, currentLocale.id);
@@ -83,14 +86,15 @@ const ReactNativeLocaleProvider = ({
8386
};
8487

8588
ReactNativeLocaleProvider.propTypes = {
86-
children: PropTypes.element,
89+
children: PropTypes.element.isRequired,
8790
initialLocaleId: PropTypes.string,
8891
locales: PropTypes.arrayOf(PropTypes.shape({
8992
id: PropTypes.string.isRequired,
9093
name: PropTypes.string.isRequired,
9194
messages: PropTypes.object.isRequired,
9295
})).isRequired,
9396
onLocaleChange: PropTypes.func,
97+
textComponent: PropTypes.elementType,
9498
};
9599

96100
export default ReactNativeLocaleProvider;

src/shared/modules/react-native-locale/LocaleProvider.test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useLocale from './use-locale';
88

99
const messages = {
1010
'en-US': { apple: 'apple' }, // Default locale
11-
'pt-PT': { apple: 'maça' },
11+
'pt-PT': { apple: 'maçã' },
1212
'ru-RU': { apple: 'яблоко' },
1313
};
1414

@@ -20,6 +20,7 @@ const locales = [
2020

2121
beforeEach(() => {
2222
jest.clearAllMocks();
23+
/* eslint-disable-next-line babel/no-unused-expressions */
2324
console.error.mockRestore?.();
2425
});
2526

@@ -30,7 +31,7 @@ it("should load matching user's device preferred locale", () => {
3031
}));
3132

3233
const { queryByText } = render(
33-
<LocaleProvider locales={ locales }>
34+
<LocaleProvider locales={ locales } textComponent={ Text }>
3435
<Text>
3536
<FormattedMessage id="apple" />
3637
</Text>
@@ -47,7 +48,7 @@ it("should load default locale if there is no matching user's device preferred l
4748
}));
4849

4950
const { queryByText } = render(
50-
<LocaleProvider locales={ locales }>
51+
<LocaleProvider locales={ locales } textComponent={ Text }>
5152
<Text>
5253
<FormattedMessage id="apple" />
5354
</Text>
@@ -59,7 +60,7 @@ it("should load default locale if there is no matching user's device preferred l
5960

6061
it('should load initial locale by id if it exists', () => {
6162
const { queryByText } = render(
62-
<LocaleProvider locales={ locales } initialLocaleId="pt-PT">
63+
<LocaleProvider locales={ locales } initialLocaleId="pt-PT" textComponent={ Text }>
6364
<Text>
6465
<FormattedMessage id="apple" />
6566
</Text>
@@ -74,7 +75,7 @@ it('should throw if initial locale id does not exist', () => {
7475

7576
expect(() =>
7677
render(
77-
<LocaleProvider locales={ locales } initialLocaleId="es-ES">
78+
<LocaleProvider locales={ locales } initialLocaleId="es-ES" textComponent={ Text }>
7879
<Text>
7980
<FormattedMessage id="apple" />
8081
</Text>
@@ -88,7 +89,7 @@ it('should throw if locales array is empty', () => {
8889

8990
expect(() =>
9091
render(
91-
<LocaleProvider locales={ [] }>
92+
<LocaleProvider locales={ [] } textComponent={ Text }>
9293
<Text>
9394
<FormattedMessage id="apple" />
9495
</Text>
@@ -115,7 +116,7 @@ it('should change locale when requested by a consumer', () => {
115116
};
116117

117118
const { getByTestId, getByText } = render(
118-
<LocaleProvider locales={ locales } initialLocaleId="en-US">
119+
<LocaleProvider locales={ locales } initialLocaleId="en-US" textComponent={ Text }>
119120
<MyComponent />
120121
</LocaleProvider>,
121122
);
@@ -145,7 +146,7 @@ it('should not change locale when a consumer requests an unknown locale', () =>
145146
};
146147

147148
const { getByTestId, getByText } = render(
148-
<LocaleProvider locales={ locales } initialLocaleId="en-US">
149+
<LocaleProvider locales={ locales } initialLocaleId="en-US" textComponent={ Text }>
149150
<MyComponent />
150151
</LocaleProvider>,
151152
);
@@ -172,7 +173,8 @@ it('should callback when locale changes', () => {
172173
<LocaleProvider
173174
locales={ locales }
174175
initialLocaleId="en-US"
175-
onLocaleChange={ onLocalChange }>
176+
onLocaleChange={ onLocalChange }
177+
textComponent={ Text }>
176178
<MyComponent />
177179
</LocaleProvider>,
178180
);
@@ -186,7 +188,7 @@ it('should callback when locale changes', () => {
186188
it('should fail if locales change but current locale does not exist', () => {
187189
jest.spyOn(console, 'error').mockImplementation(() => {});
188190

189-
const { rerender } = render(<LocaleProvider locales={ locales } />);
191+
const { rerender } = render(<LocaleProvider locales={ locales } textComponent={ Text } />);
190192

191193
expect(() => {
192194
rerender(<LocaleProvider locales={ locales.slice(1) } />);

src/shared/test-utils/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { Text } from 'react-native';
23
import PropTypes from 'prop-types';
34
import { render } from '@testing-library/react-native';
45
import { SafeAreaProvider } from 'react-native-safe-area-context';
@@ -18,6 +19,23 @@ const localeConfig = {
1819
messages: idObj,
1920
},
2021
],
22+
// Consider the following React code:
23+
//
24+
// <Text>
25+
// <FormattedMessage id="foo" />
26+
// </Text>
27+
//
28+
// In this case, the "foo" key will resolve into the text "bar", and the following will be rendered:
29+
//
30+
// <Text>
31+
// <Text>
32+
// bar
33+
// </Text>
34+
// </Text>
35+
//
36+
// This a is necessary workaround because *ByText queries can only look up a string if it's
37+
// a direct child of a Text component.
38+
textComponent: Text,
2139
};
2240

2341
const Providers = ({ children }) => (
@@ -38,7 +56,7 @@ Providers.propTypes = {
3856

3957
const customRender = (ui, options) => render(ui, { wrapper: Providers, ...options });
4058

41-
// re-export everything
59+
// Export everything from NTL
4260
export * from '@testing-library/react-native';
4361

4462
// Override render method

0 commit comments

Comments
 (0)