Skip to content

Commit 9f85aa3

Browse files
committed
fix: update tests
1 parent ca2e87f commit 9f85aa3

23 files changed

+3032
-1970
lines changed

src/components/__tests__/Appbar/Appbar.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import Searchbar from '../../Searchbar';
2020
import Tooltip from '../../Tooltip/Tooltip';
2121
import Text from '../../Typography/Text';
2222

23-
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
24-
2523
const renderAppbarContent = utilRenderAppbarContent as (
2624
props: Parameters<typeof utilRenderAppbarContent>[0]
2725
) => { props: any }[];

src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,23 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
565565
<View
566566
collapsable={false}
567567
style={
568-
{
569-
"bottom": 0,
570-
"left": 0,
571-
"opacity": 1,
572-
"position": "absolute",
573-
"right": 0,
574-
"top": 0,
575-
"transform": [
576-
{
577-
"rotate": "0deg",
578-
},
579-
],
580-
}
568+
[
569+
{
570+
"bottom": 0,
571+
"left": 0,
572+
"position": "absolute",
573+
"right": 0,
574+
"top": 0,
575+
},
576+
{
577+
"opacity": 1,
578+
"transform": [
579+
{
580+
"rotate": "0deg",
581+
},
582+
],
583+
},
584+
]
581585
}
582586
testID="cross-fade-icon-current"
583587
>
@@ -808,19 +812,23 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
808812
<View
809813
collapsable={false}
810814
style={
811-
{
812-
"bottom": 0,
813-
"left": 0,
814-
"opacity": 1,
815-
"position": "absolute",
816-
"right": 0,
817-
"top": 0,
818-
"transform": [
819-
{
820-
"rotate": "0deg",
821-
},
822-
],
823-
}
815+
[
816+
{
817+
"bottom": 0,
818+
"left": 0,
819+
"position": "absolute",
820+
"right": 0,
821+
"top": 0,
822+
},
823+
{
824+
"opacity": 1,
825+
"transform": [
826+
{
827+
"rotate": "0deg",
828+
},
829+
],
830+
},
831+
]
824832
}
825833
testID="cross-fade-icon-current"
826834
>

src/components/__tests__/Badge.test.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import { render } from '@testing-library/react-native';
55
import { red500 } from '../../styles/themes/v2/colors';
66
import Badge from '../Badge';
77

8-
jest.mock('react-native', () => {
9-
const RN = jest.requireActual('react-native');
10-
11-
RN.Dimensions.get = () => ({
12-
fontScale: 1,
13-
});
14-
15-
return RN;
16-
});
17-
188
it('renders badge', () => {
199
const tree = render(<Badge />).toJSON();
2010

src/components/__tests__/BottomNavigation.test.tsx

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,58 +29,6 @@ declare global {
2929
}
3030
}
3131

32-
type AnimatedTiming = (
33-
value: Animated.Value | Animated.ValueXY,
34-
config: Animated.TimingAnimationConfig
35-
) => Animated.CompositeAnimation;
36-
37-
type AnimatedParallel = (animations: Array<Animated.CompositeAnimation>) => {
38-
start: (callback?: Animated.EndCallback) => void;
39-
};
40-
41-
// Make sure any animation finishes before checking the snapshot results
42-
jest.mock('react-native', () => {
43-
const RN = jest.requireActual('react-native');
44-
45-
const timing: AnimatedTiming = (value, config) => ({
46-
start: (callback) => {
47-
value.setValue(config.toValue as any);
48-
callback?.({ finished: true });
49-
},
50-
value,
51-
config,
52-
stop: () => {
53-
throw new Error('Not implemented');
54-
},
55-
reset: () => {
56-
throw new Error('Not implemented');
57-
},
58-
});
59-
RN.Animated.timing = timing;
60-
61-
const parallel: AnimatedParallel = (animations) => ({
62-
start: (callback) => {
63-
const results = animations.map((animation) => {
64-
animation.start();
65-
return { finished: true };
66-
});
67-
callback?.({ finished: results.every((result) => result.finished) });
68-
},
69-
});
70-
71-
RN.Animated.parallel = parallel;
72-
73-
RN.Dimensions.get = () => ({
74-
fontScale: 1,
75-
});
76-
77-
return RN;
78-
});
79-
80-
jest.mock('react-native-safe-area-context', () => ({
81-
useSafeAreaInsets: () => ({ bottom: 0, left: 0, right: 0, top: 0 }),
82-
}));
83-
8432
const icons = ['magnify', 'camera', 'inbox', 'heart', 'shopping-music'];
8533

8634
const createState = (index: number, length: number) => ({

src/components/__tests__/DataTable.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import * as React from 'react';
22

33
import { render } from '@testing-library/react-native';
4-
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
54

65
import Checkbox from '../Checkbox';
76
import DataTable from '../DataTable/DataTable';
87

9-
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
10-
118
describe('DataTable.Header', () => {
129
it('renders data table header', () => {
1310
const tree = render(

src/components/__tests__/Dialog.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import { act, fireEvent, render } from '@testing-library/react-native';
1212
import Dialog from '../../components/Dialog/Dialog';
1313
import Button from '../Button/Button';
1414

15-
jest.mock('react-native-safe-area-context', () => ({
16-
useSafeAreaInsets: () => ({ bottom: 44, left: 0, right: 0, top: 37 }),
17-
}));
18-
1915
jest.mock('react-native/Libraries/Utilities/BackHandler', () =>
2016
// eslint-disable-next-line jest/no-mocks-import
2117
require('react-native/Libraries/Utilities/__mocks__/BackHandler')

src/components/__tests__/FABGroup.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { getTheme } from '../../core/theming';
88
import FAB from '../FAB';
99
import { getFABGroupColors } from '../FAB/utils';
1010

11-
jest.mock('react-native-safe-area-context', () => ({
12-
useSafeAreaInsets: () => ({ bottom: 34, left: 0, right: 0, top: 47 }),
13-
}));
14-
1511
describe('getFABGroupColors - backdrop color', () => {
1612
it('should return custom color', () => {
1713
expect(

src/components/__tests__/Menu.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import * as React from 'react';
22
import { Animated, StyleSheet, View } from 'react-native';
33

44
import { act, render, screen, waitFor } from '@testing-library/react-native';
5-
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
65

76
import { getTheme } from '../../core/theming';
87
import { MD3Elevation } from '../../types';
98
import Button from '../Button/Button';
109
import Menu, { ELEVATION_LEVELS_MAP } from '../Menu/Menu';
1110
import Portal from '../Portal/Portal';
1211

13-
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
14-
1512
const styles = StyleSheet.create({
1613
contentStyle: {
1714
borderTopLeftRadius: 0,

src/components/__tests__/Snackbar.test.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,6 @@ const styles = StyleSheet.create({
1818
text: { color: white, marginLeft: 10, flexWrap: 'wrap', flexShrink: 1 },
1919
});
2020

21-
// Make sure any animation finishes before checking the snapshot results
22-
jest.mock('react-native', () => {
23-
const RN = jest.requireActual('react-native');
24-
25-
const timing: (typeof Animated)['timing'] = (value, config) => ({
26-
start: (callback) => {
27-
value.setValue(config.toValue as any);
28-
callback?.({ finished: true });
29-
},
30-
value,
31-
config,
32-
stop: () => {
33-
throw new Error('Not implemented');
34-
},
35-
reset: () => {
36-
throw new Error('Not implemented');
37-
},
38-
});
39-
RN.Animated.timing = timing;
40-
41-
return RN;
42-
});
43-
4421
jest.mock('react-native-safe-area-context', () => ({
4522
useSafeAreaInsets: () => ({ bottom: 34, left: 0, right: 0, top: 47 }),
4623
}));

src/components/__tests__/Tooltip.test.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@ import {
66
render,
77
waitForElementToBeRemoved,
88
} from '@testing-library/react-native';
9-
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
109

1110
import PaperProvider from '../../core/PaperProvider';
1211
import Tooltip from '../Tooltip/Tooltip';
1312

1413
const mockedRemoveEventListener = jest.fn();
1514

16-
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
17-
18-
jest.mock('react-native', () => {
19-
const RN = jest.requireActual('react-native');
20-
21-
RN.Dimensions.addEventListener = () => ({
15+
jest.mock('../../utils/addEventListener', () => ({
16+
addEventListener: () => ({
2217
remove: mockedRemoveEventListener,
23-
});
24-
25-
return RN;
26-
});
18+
}),
19+
}));
2720

2821
const DummyComponent = React.forwardRef<View>((props, ref) => (
2922
<View {...props} ref={ref as RefObject<View>}>

0 commit comments

Comments
 (0)