diff --git a/src/components/Menu/Menu.tsx b/src/components/Menu/Menu.tsx index 925ca50f86..a019c0fb04 100644 --- a/src/components/Menu/Menu.tsx +++ b/src/components/Menu/Menu.tsx @@ -629,6 +629,7 @@ class Menu extends React.Component { style={[styles.wrapper, positionStyle, style]} pointerEvents={visible ? 'box-none' : 'none'} onAccessibilityEscape={onDismiss} + testID={`${testID}-view`} > { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders hidden indicator', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders large indicator', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders colored indicator', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/AnimatedFAB.test.tsx b/src/components/__tests__/AnimatedFAB.test.tsx index 6d1e4cbc1f..e6e3711663 100644 --- a/src/components/__tests__/AnimatedFAB.test.tsx +++ b/src/components/__tests__/AnimatedFAB.test.tsx @@ -4,7 +4,6 @@ import * as React from 'react'; import { Animated, StyleSheet } from 'react-native'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import { MD3Colors } from '../../styles/themes/v3/tokens'; import AnimatedFAB from '../FAB/AnimatedFAB'; @@ -16,37 +15,31 @@ const styles = StyleSheet.create({ }); it('renders animated fab', () => { - const tree = renderer - .create( - {}} label="" extended={false} icon="plus" /> - ) - .toJSON(); + const tree = render( + {}} label="" extended={false} icon="plus" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders animated fab with label on the right by default', () => { - const tree = renderer - .create( - {}} icon="plus" /> - ) - .toJSON(); + const tree = render( + {}} icon="plus" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders animated fab with label on the left', () => { - const tree = renderer - .create( - {}} - icon="plus" - /> - ) - .toJSON(); + const tree = render( + {}} + icon="plus" + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Appbar/Appbar.test.tsx b/src/components/__tests__/Appbar/Appbar.test.tsx index 1b8e2d7cfa..bf368ec11a 100644 --- a/src/components/__tests__/Appbar/Appbar.test.tsx +++ b/src/components/__tests__/Appbar/Appbar.test.tsx @@ -3,7 +3,6 @@ import { Animated, Platform } from 'react-native'; import { render } from '@testing-library/react-native'; import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock'; -import renderer from 'react-test-renderer'; import Provider from '../../../core/Provider'; import { getTheme } from '../../../core/theming'; @@ -33,27 +32,23 @@ const renderAppbarContent = utilRenderAppbarContent as ( describe('Appbar', () => { it('does not pass any additional props to Searchbar', () => { - const tree = renderer - .create( - - - - ) - .toJSON(); + const tree = render( + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('passes additional props to AppbarBackAction, AppbarContent and AppbarAction', () => { - const tree = renderer - .create( - - {}} /> - - {}} /> - - ) - .toJSON(); + const tree = render( + + {}} /> + + {}} /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Avatar.test.tsx b/src/components/__tests__/Avatar.test.tsx index d24fed5701..96d69582b6 100644 --- a/src/components/__tests__/Avatar.test.tsx +++ b/src/components/__tests__/Avatar.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; import { fireEvent, render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import { red500 } from '../../styles/themes/v2/colors'; import * as Avatar from '../Avatar/Avatar'; @@ -14,51 +13,47 @@ const styles = StyleSheet.create({ }); it('renders avatar with text', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with text and custom size', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with text and custom background color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with text and custom colors', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with icon', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with icon and custom background color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders avatar with image', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Badge.test.tsx b/src/components/__tests__/Badge.test.tsx index c318ce1788..aaf42b138b 100644 --- a/src/components/__tests__/Badge.test.tsx +++ b/src/components/__tests__/Badge.test.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import { red500 } from '../../styles/themes/v2/colors'; import Badge from '../Badge'; @@ -16,39 +16,37 @@ jest.mock('react-native', () => { }); it('renders badge', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders badge with content', () => { - const tree = renderer.create(3).toJSON(); + const tree = render(3).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders badge in different size', () => { - const tree = renderer.create(3).toJSON(); + const tree = render(3).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders badge as hidden', () => { - const tree = renderer - .create( - - 3 - - ) - .toJSON(); + const tree = render( + + 3 + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders badge in different color', () => { - const tree = renderer - .create(3) - .toJSON(); + const tree = render( + 3 + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Banner.test.tsx b/src/components/__tests__/Banner.test.tsx index 2c71988b87..4024b53b52 100644 --- a/src/components/__tests__/Banner.test.tsx +++ b/src/components/__tests__/Banner.test.tsx @@ -2,118 +2,105 @@ import * as React from 'react'; import { Animated, Image } from 'react-native'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import Banner from '../Banner'; it('renders hidden banner, without action buttons and without image', () => { - const tree = renderer - .create( - - Two line text string with two actions. One to two lines is preferable on - mobile. - - ) - .toJSON(); + const tree = render( + + Two line text string with two actions. One to two lines is preferable on + mobile. + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders visible banner, without action buttons and without image', () => { - const tree = renderer - .create( - - Two line text string with two actions. One to two lines is preferable on - mobile. - - ) - .toJSON(); + const tree = render( + + Two line text string with two actions. One to two lines is preferable on + mobile. + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders visible banner, with action buttons and without image', () => { - const tree = renderer - .create( - {} }, - { label: 'second', onPress: () => {} }, - ]} - > - Two line text string with two actions. One to two lines is preferable on - mobile. - - ) - .toJSON(); + const tree = render( + {} }, + { label: 'second', onPress: () => {} }, + ]} + > + Two line text string with two actions. One to two lines is preferable on + mobile. + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders visible banner, without action buttons and with image', () => { - const tree = renderer - .create( - ( - - )} - > - Two line text string with two actions. One to two lines is preferable on - mobile. - - ) - .toJSON(); + const tree = render( + ( + + )} + > + Two line text string with two actions. One to two lines is preferable on + mobile. + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders visible banner, with action buttons and with image', () => { - const tree = renderer - .create( - ( - - )} - actions={[{ label: 'first', onPress: () => {} }]} - > - Two line text string with two actions. One to two lines is preferable on - mobile. - - ) - .toJSON(); + const tree = render( + ( + + )} + actions={[{ label: 'first', onPress: () => {} }]} + > + Two line text string with two actions. One to two lines is preferable on + mobile. + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('render visible banner, with custom theme', () => { - const tree = renderer - .create( - {} }]} - > - Custom theme - - ) - .toJSON(); + const tree = render( + {} }]} + > + Custom theme + + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -140,7 +127,7 @@ describe('animations', () => { describe('when component is rendered hidden', () => { // This behaviour is probably a bug. Needs triage before next version. it('will fire onHideAnimationFinished on mount', () => { - renderer.create( + render( { }); it('should fire onShowAnimationFinished upon opening', () => { - const tree = renderer.create( + const tree = render( { describe('when component is rendered visible', () => { // This behaviour is probably a bug. Needs triage before next version. it('will fire onShowAnimationFinished on mount', () => { - renderer.create( + render( { }); it('should fire onHideAnimationFinished upon closing', () => { - const tree = renderer.create( + const tree = render( { describe('when the callbacks change while the component is mounted', () => { it('should not cause another open/close animation', () => { - const tree = renderer.create( + const tree = render( { }); it('should use the new callbacks upon opening/closing', () => { - const tree = renderer.create( + const tree = render( ({ }); it('renders shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - /> - ) - .toJSON(); + const tree = render( + route.title} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders bottom navigation with scene animation', () => { - const tree = renderer - .create( - route.title} - /> - ) - .toJSON(); + const tree = render( + route.title} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -246,16 +241,14 @@ it('calls onTabLongPress', () => { }); it('renders non-shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - /> - ) - .toJSON(); + const tree = render( + route.title} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -280,109 +273,97 @@ it('does not crash when shifting is true and the number of tabs in the navigatio }); it('renders custom icon and label in shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - renderIcon={({ route, color }) => ( - - )} - renderLabel={({ route, color }) => ( - {route.title} - )} - /> - ) - .toJSON(); + const tree = render( + route.title} + renderIcon={({ route, color }) => ( + + )} + renderLabel={({ route, color }) => ( + {route.title} + )} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders custom icon and label in non-shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - renderIcon={({ route, color }) => ( - - )} - renderLabel={({ route, color }) => ( - {route.title} - )} - /> - ) - .toJSON(); + const tree = render( + route.title} + renderIcon={({ route, color }) => ( + + )} + renderLabel={({ route, color }) => ( + {route.title} + )} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders custom icon and label with custom colors in shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - activeColor="#FBF7DB" - inactiveColor="#853D4B" - /> - ) - .toJSON(); + const tree = render( + route.title} + activeColor="#FBF7DB" + inactiveColor="#853D4B" + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders custom icon and label with custom colors in non-shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - activeColor="#FBF7DB" - inactiveColor="#853D4B" - /> - ) - .toJSON(); + const tree = render( + route.title} + activeColor="#FBF7DB" + inactiveColor="#853D4B" + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('hides labels in shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - /> - ) - .toJSON(); + const tree = render( + route.title} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('hides labels in non-shifting bottom navigation', () => { - const tree = renderer - .create( - route.title} - /> - ) - .toJSON(); + const tree = render( + route.title} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -644,16 +625,14 @@ it("allows customizing Route's type via generics", () => { ], }; - const tree = renderer - .create( - route.customPropertyName} - renderScene={({ route }) => route.customPropertyName} - /> - ) - .toJSON(); + const tree = render( + route.customPropertyName} + renderScene={({ route }) => route.customPropertyName} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Button.test.tsx b/src/components/__tests__/Button.test.tsx index 0ea394e055..6055addbe2 100644 --- a/src/components/__tests__/Button.test.tsx +++ b/src/components/__tests__/Button.test.tsx @@ -3,7 +3,6 @@ import { Animated, StyleSheet } from 'react-native'; import { fireEvent, render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { pink500, black, white } from '../../styles/themes/v2/colors'; @@ -17,113 +16,99 @@ const styles = StyleSheet.create({ }); it('renders text button by default', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders text button with mode', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders outlined button with mode', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders contained contained with mode', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with icon', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with icon in reverse order', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders loading button', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled button', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with button color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with custom testID', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with an accessibility label', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders button with an accessibility hint', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Card/Card.test.tsx b/src/components/__tests__/Card/Card.test.tsx index cf4701ab12..48b298ada0 100644 --- a/src/components/__tests__/Card/Card.test.tsx +++ b/src/components/__tests__/Card/Card.test.tsx @@ -3,7 +3,6 @@ import { Animated, StyleSheet, Text } from 'react-native'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../../core/theming'; import { black, white } from '../../../styles/themes/v2/colors'; @@ -23,7 +22,7 @@ const styles = StyleSheet.create({ describe('Card', () => { it('renders an outlined card', () => { - const tree = renderer.create({null}).toJSON(); + const tree = render({null}).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Checkbox/Checkbox.test.tsx b/src/components/__tests__/Checkbox/Checkbox.test.tsx index 164175299e..efa819007e 100644 --- a/src/components/__tests__/Checkbox/Checkbox.test.tsx +++ b/src/components/__tests__/Checkbox/Checkbox.test.tsx @@ -1,61 +1,55 @@ import * as React from 'react'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import Checkbox from '../../Checkbox'; it('renders checked Checkbox with onPress', () => { - const tree = renderer - .create( {}} />) - .toJSON(); + const tree = render( + {}} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders unchecked Checkbox with onPress', () => { - const tree = renderer - .create( {}} />) - .toJSON(); + const tree = render( + {}} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders indeterminate Checkbox', () => { - const tree = renderer - .create( {}} />) - .toJSON(); + const tree = render( + {}} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders checked Checkbox with color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders unchecked Checkbox with color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders indeterminate Checkbox with color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders Checkbox with custom testID', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Checkbox/CheckboxItem.test.tsx b/src/components/__tests__/Checkbox/CheckboxItem.test.tsx index 83d9cef391..23e247d9cc 100644 --- a/src/components/__tests__/Checkbox/CheckboxItem.test.tsx +++ b/src/components/__tests__/Checkbox/CheckboxItem.test.tsx @@ -2,52 +2,45 @@ import * as React from 'react'; import { Platform } from 'react-native'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import Checkbox from '../../Checkbox'; it('renders unchecked', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render the iOS checkbox on different platforms', () => { Platform.OS = 'android'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render the Android checkbox on different platforms', () => { Platform.OS = 'ios'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render leading checkbox control', () => { Platform.OS = 'ios'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Chip.test.tsx b/src/components/__tests__/Chip.test.tsx index 73eb76d72d..e05096ce58 100644 --- a/src/components/__tests__/Chip.test.tsx +++ b/src/components/__tests__/Chip.test.tsx @@ -3,7 +3,6 @@ import { Animated } from 'react-native'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { black, white } from '../../styles/themes/v2/colors'; @@ -11,59 +10,49 @@ import Chip from '../Chip/Chip'; import { getChipColors } from '../Chip/helpers'; it('renders chip with onPress', () => { - const tree = renderer - .create( {}}>Example Chip) - .toJSON(); + const tree = render( {}}>Example Chip).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders chip with icon', () => { - const tree = renderer - .create(Example Chip) - .toJSON(); + const tree = render(Example Chip).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders chip with close button', () => { - const tree = renderer - .create( - {}}> - Example Chip - - ) - .toJSON(); + const tree = render( + {}}> + Example Chip + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders chip with custom close button', () => { - const tree = renderer - .create( - {}} closeIcon="arrow-down"> - Example Chip - - ) - .toJSON(); + const tree = render( + {}} closeIcon="arrow-down"> + Example Chip + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders outlined disabled chip', () => { - const tree = renderer - .create( - - Example Chip - - ) - .toJSON(); + const tree = render( + + Example Chip + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders selected chip', () => { - const tree = renderer.create(Example Chip).toJSON(); + const tree = render(Example Chip).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/DataTable.test.tsx b/src/components/__tests__/DataTable.test.tsx index 41a60b9693..a2c7866c6b 100644 --- a/src/components/__tests__/DataTable.test.tsx +++ b/src/components/__tests__/DataTable.test.tsx @@ -1,94 +1,75 @@ import * as React from 'react'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import DataTable from '../DataTable/DataTable'; it('renders data table header', () => { - const tree = renderer - .create( - - Dessert - Calories - - ) - .toJSON(); + const tree = render( + + Dessert + Calories + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders data table title with sort icon', () => { - const tree = renderer - .create( - Dessert - ) - .toJSON(); + const tree = render( + Dessert + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders right aligned data table title', () => { - const tree = renderer - .create(Calories) - .toJSON(); + const tree = render( + Calories + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders data table title with press handler', () => { - const tree = renderer - .create( - {}}> - Dessert - - ) - .toJSON(); + const tree = render( + {}}> + Dessert + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders data table cell', () => { - const tree = renderer - .create(Cupcake) - .toJSON(); + const tree = render(Cupcake).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders right aligned data table cell', () => { - const tree = renderer - .create(356) - .toJSON(); + const tree = render(356).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders data table pagination', () => { - const tree = renderer - .create( - {}} - /> - ) - .toJSON(); + const tree = render( + {}} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders data table pagination with label', () => { - const tree = renderer - .create( - {}} - label="11-20 of 150" - /> - ) - .toJSON(); + const tree = render( + {}} + label="11-20 of 150" + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Drawer/DrawerSection.test.tsx b/src/components/__tests__/Drawer/DrawerSection.test.tsx index 333cb30b88..e74cf362c6 100644 --- a/src/components/__tests__/Drawer/DrawerSection.test.tsx +++ b/src/components/__tests__/Drawer/DrawerSection.test.tsx @@ -1,19 +1,17 @@ import React from 'react'; import { View } from 'react-native'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import DrawerSection from '../../Drawer/DrawerSection'; describe('DrawerSection', () => { it('renders properly', () => { - const tree = renderer - .create( - - - - ) - .toJSON(); + const tree = render( + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/DrawerItem.test.tsx b/src/components/__tests__/DrawerItem.test.tsx index d558aac5b4..ec4a36efcb 100644 --- a/src/components/__tests__/DrawerItem.test.tsx +++ b/src/components/__tests__/DrawerItem.test.tsx @@ -1,29 +1,29 @@ import * as React from 'react'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import DrawerItem from '../Drawer/DrawerItem'; it('renders basic DrawerItem', () => { - const tree = renderer - .create( {}} label="Example item" />) - .toJSON(); + const tree = render( + {}} label="Example item" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders DrawerItem with icon', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders active DrawerItem', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 32d1e46684..8e8dcb644d 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -3,7 +3,6 @@ import { Animated, StyleSheet } from 'react-native'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { black, white } from '../../styles/themes/v2/colors'; @@ -33,98 +32,90 @@ const styles = StyleSheet.create({ }); it('renders default FAB', () => { - const tree = renderer.create( {}} icon="plus" />).toJSON(); + const tree = render( {}} icon="plus" />).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders small FAB', () => { - const tree = renderer - .create( {}} icon="plus" />) - .toJSON(); + const tree = render( + {}} icon="plus" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders large FAB', () => { - const tree = renderer - .create( {}} icon="plus" />) - .toJSON(); + const tree = render( + {}} icon="plus" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders FAB with custom size prop', () => { - const tree = renderer - .create( {}} icon="plus" />) - .toJSON(); + const tree = render( + {}} icon="plus" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders extended FAB', () => { - const tree = renderer - .create( {}} icon="plus" label="Add items" />) - .toJSON(); + const tree = render( + {}} icon="plus" label="Add items" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders extended FAB with custom size prop', () => { - const tree = renderer - .create( - {}} icon="plus" label="Add items" /> - ) - .toJSON(); + const tree = render( + {}} icon="plus" label="Add items" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders loading FAB', () => { - const tree = renderer - .create( {}} icon="plus" loading={true} />) - .toJSON(); + const tree = render( + {}} icon="plus" loading={true} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders loading FAB with custom size prop', () => { - const tree = renderer - .create( - {}} icon="plus" loading={true} /> - ) - .toJSON(); + const tree = render( + {}} icon="plus" loading={true} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled FAB', () => { - const tree = renderer - .create( {}} icon="plus" disabled />) - .toJSON(); + const tree = render( {}} icon="plus" disabled />).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders custom color for the icon and label of the FAB', () => { - const tree = renderer - .create( {}} icon="plus" color="#AA0114" />) - .toJSON(); + const tree = render( + {}} icon="plus" color="#AA0114" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders not visible FAB', () => { - const { update, toJSON } = renderer.create( - {}} icon="plus" /> - ); + const { update, toJSON } = render( {}} icon="plus" />); update( {}} icon="plus" visible={false} />); expect(toJSON()).toMatchSnapshot(); }); it('renders visible FAB', () => { - const { update, toJSON } = renderer.create( + const { update, toJSON } = render( {}} icon="plus" visible={false} /> ); diff --git a/src/components/__tests__/IconButton.test.tsx b/src/components/__tests__/IconButton.test.tsx index bf9fa54e97..b846041616 100644 --- a/src/components/__tests__/IconButton.test.tsx +++ b/src/components/__tests__/IconButton.test.tsx @@ -3,7 +3,6 @@ import { Animated, StyleSheet } from 'react-native'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { pink500 } from '../../styles/themes/v2/colors'; @@ -17,33 +16,33 @@ const styles = StyleSheet.create({ }); it('renders icon button by default', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders icon button with color', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders icon button with size', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled icon button', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders icon change animated', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 2ec12dfc2a..c9fe8d6d10 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -1,8 +1,8 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; +import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { red500 } from '../../styles/themes/v2/colors'; @@ -18,78 +18,68 @@ const styles = StyleSheet.create({ }); it('renders list accordion with children', () => { - const tree = renderer - .create( - } - title="Expandable list item" - > - - - ) - .toJSON(); + const tree = render( + } + title="Expandable list item" + > + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders multiline list accordion', () => { - const tree = renderer - .create( - - - - ) - .toJSON(); + const tree = render( + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list accordion with left items', () => { - const tree = renderer - .create( - } - title="Accordion item 1" - > - } - title="List item 1" - /> - - ) - .toJSON(); + const tree = render( + } + title="Accordion item 1" + > + } + title="List item 1" + /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders expanded accordion', () => { - const tree = renderer - .create( - - - - ) - .toJSON(); + const tree = render( + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list accordion with custom title and description styles', () => { - const tree = renderer - .create( - - - - ) - .toJSON(); + const tree = render( + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 118c3a7ee9..5f09c6658d 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; import { Text, View } from 'react-native'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import { red500 } from '../../styles/themes/v2/colors'; import Chip from '../Chip/Chip'; @@ -19,106 +19,94 @@ const styles = StyleSheet.create({ }); it('renders list item with title and description', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list item with left item', () => { - const tree = renderer - .create( - } - /> - ) - .toJSON(); + const tree = render( + } + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list item with right item', () => { - const tree = renderer - .create( GG} />) - .toJSON(); + const tree = render( + GG} /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list item with left and right items', () => { - const tree = renderer - .create( - GG} - right={(props) => } - /> - ) - .toJSON(); + const tree = render( + GG} + right={(props) => } + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list item with custom title and description styles', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list item with custom description', () => { - const tree = renderer - .create( - ( + const tree = render( + ( + + + React Native Paper is a high-quality, standard-compliant Design + Design library that has you covered in all major use-cases. + - - React Native Paper is a high-quality, standard-compliant Design - Design library that has you covered in all major use-cases. - - - {}}> - DOCS.pdf - - + {}}> + DOCS.pdf + - )} - /> - ) - .toJSON(); + + )} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders with a description with typeof number', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/ListSection.test.tsx b/src/components/__tests__/ListSection.test.tsx index 1da417d8ac..7e90e791af 100644 --- a/src/components/__tests__/ListSection.test.tsx +++ b/src/components/__tests__/ListSection.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import { red500 } from '../../styles/themes/v2/colors'; import ListIcon from '../List/ListIcon'; @@ -16,59 +16,53 @@ const styles = StyleSheet.create({ }); it('renders list section without subheader', () => { - const tree = renderer - .create( - - } - /> - } - /> - - ) - .toJSON(); + const tree = render( + + } + /> + } + /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list section with subheader', () => { - const tree = renderer - .create( - - Some title - } - /> - } - /> - - ) - .toJSON(); + const tree = render( + + Some title + } + /> + } + /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders list section with custom title style', () => { - const tree = renderer - .create( - - } - /> - } - /> - - ) - .toJSON(); + const tree = render( + + } + /> + } + /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Menu.test.tsx b/src/components/__tests__/Menu.test.tsx index 116a2386df..b27027b0fc 100644 --- a/src/components/__tests__/Menu.test.tsx +++ b/src/components/__tests__/Menu.test.tsx @@ -1,8 +1,7 @@ import * as React from 'react'; import { Animated, StyleSheet, View } from 'react-native'; -import { render, waitFor } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; +import { render, waitFor, screen } from '@testing-library/react-native'; import Button from '../Button/Button'; import Menu from '../Menu/Menu'; @@ -16,59 +15,53 @@ const styles = StyleSheet.create({ }); it('renders visible menu', () => { - const tree = renderer - .create( - - Open menu} - > - - - - - ) - .toJSON(); + const tree = render( + + Open menu} + > + + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders not visible menu', () => { - const tree = renderer - .create( - - Open menu} - > - - - - - ) - .toJSON(); + const tree = render( + + Open menu} + > + + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders menu with content styles', () => { - const tree = renderer - .create( - - Open menu} - contentStyle={styles.contentStyle} - > - - - - - ) - .toJSON(); + const tree = render( + + Open menu} + contentStyle={styles.contentStyle} + > + + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -94,7 +87,7 @@ it('uses the default anchorPosition of top', async () => { ); } - const tree = renderer.create(makeMenu(false)); + render(makeMenu(false)); jest .spyOn(View.prototype, 'measureInWindow') @@ -104,22 +97,15 @@ it('uses the default anchorPosition of top', async () => { // componentDidUpdate isn't called by default in jest. Forcing the update // than triggers measureInWindow, which is how Menu decides where to show // itself. - tree.update(makeMenu(true)); + screen.update(makeMenu(true)); - // If someone has a better way to verify the location of a child on the - // screen, please by all means let me know. await waitFor(() => { - const menu = tree.root.findByProps({ accessibilityViewIsModal: true }); - expect(menu).toHaveProperty('_fiber.pendingProps.style', [ - { - position: 'absolute', - }, - { - left: 100, - top: 100, - }, - undefined, - ]); + const menu = screen.getByTestId('menu-view'); + expect(menu).toHaveStyle({ + position: 'absolute', + left: 100, + top: 100, + }); }); }); @@ -145,27 +131,21 @@ it('respects anchorPosition bottom', async () => { ); } - const tree = renderer.create(makeMenu(false)); + render(makeMenu(false)); jest .spyOn(View.prototype, 'measureInWindow') .mockImplementation((fn) => fn(100, 100, 80, 32)); - // See note from previous test about this update. - tree.update(makeMenu(true)); + screen.update(makeMenu(true)); await waitFor(() => { - const menu = tree.root.findByProps({ accessibilityViewIsModal: true }); - expect(menu).toHaveProperty('_fiber.pendingProps.style', [ - { - position: 'absolute', - }, - { - left: 100, - top: 132, - }, - undefined, - ]); + const menu = screen.getByTestId('menu-view'); + expect(menu).toHaveStyle({ + position: 'absolute', + left: 100, + top: 132, + }); }); }); diff --git a/src/components/__tests__/MenuItem.test.tsx b/src/components/__tests__/MenuItem.test.tsx index ec0fecc90e..f9121da469 100644 --- a/src/components/__tests__/MenuItem.test.tsx +++ b/src/components/__tests__/MenuItem.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { black, white } from '../../styles/themes/v2/colors'; @@ -11,27 +10,25 @@ import { getMenuItemColor } from '../Menu/utils'; describe('Menu Item', () => { it('renders menu item', () => { - const tree = renderer - .create( - <> - {}} title="Redo" /> - {}} title="Undo" /> - {}} - title="Cut" - disabled - /> - {}} - title="Copy" - disabled - /> - {}} title="Paste" /> - - ) - .toJSON(); + const tree = render( + <> + {}} title="Redo" /> + {}} title="Undo" /> + {}} + title="Cut" + disabled + /> + {}} + title="Copy" + disabled + /> + {}} title="Paste" /> + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/RadioButton/RadioButton.test.tsx b/src/components/__tests__/RadioButton/RadioButton.test.tsx index e28362a62b..ecba6bf851 100644 --- a/src/components/__tests__/RadioButton/RadioButton.test.tsx +++ b/src/components/__tests__/RadioButton/RadioButton.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import RadioButton from '../../RadioButton'; import { RadioButtonContext } from '../../RadioButton/RadioButtonGroup'; @@ -20,7 +20,7 @@ describe('RadioButton', () => { }); it('renders properly', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); @@ -40,7 +40,7 @@ describe('RadioButton', () => { }); it('renders properly', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); @@ -48,15 +48,13 @@ describe('RadioButton', () => { describe('when RadioButton is wrapped by RadioButtonContext.Provider', () => { it('renders properly', () => { - const tree = renderer - .create( - {} }} - > - - - ) - .toJSON(); + const tree = render( + {} }} + > + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -64,9 +62,9 @@ describe('RadioButton', () => { describe('RadioButton with custom testID', () => { it('renders properly', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/RadioButton/RadioButtonGroup.test.tsx b/src/components/__tests__/RadioButton/RadioButtonGroup.test.tsx index 34bdd5abb7..2b431102cb 100644 --- a/src/components/__tests__/RadioButton/RadioButtonGroup.test.tsx +++ b/src/components/__tests__/RadioButton/RadioButtonGroup.test.tsx @@ -1,18 +1,16 @@ import React from 'react'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import RadioButton from '../../RadioButton'; describe('RadioButtonGroup', () => { it('renders properly', () => { - const tree = renderer - .create( - {}}> - - - ) - .toJSON(); + const tree = render( + {}}> + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/RadioButton/RadioButtonItem.test.tsx b/src/components/__tests__/RadioButton/RadioButtonItem.test.tsx index a2678cd775..ed790d0256 100644 --- a/src/components/__tests__/RadioButton/RadioButtonItem.test.tsx +++ b/src/components/__tests__/RadioButton/RadioButtonItem.test.tsx @@ -1,68 +1,60 @@ import * as React from 'react'; import { Platform } from 'react-native'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import RadioButton from '../../RadioButton'; it('renders unchecked', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render the iOS radio button on different platforms', () => { Platform.OS = 'android'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render the Android radio button on different platforms', () => { Platform.OS = 'ios'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('can render leading radio button control', () => { Platform.OS = 'ios'; - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Searchbar.test.tsx b/src/components/__tests__/Searchbar.test.tsx index fffd1032c5..a9bf8ce6e1 100644 --- a/src/components/__tests__/Searchbar.test.tsx +++ b/src/components/__tests__/Searchbar.test.tsx @@ -2,29 +2,26 @@ import * as React from 'react'; import { Animated } from 'react-native'; import { fireEvent, render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import * as Avatar from '../Avatar/Avatar'; import Searchbar from '../Searchbar'; it('renders with placeholder', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders with text', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('activity indicator snapshot test', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/SegmentedButton.test.tsx b/src/components/__tests__/SegmentedButton.test.tsx index 2a3f169c7b..2e96e7bdb9 100644 --- a/src/components/__tests__/SegmentedButton.test.tsx +++ b/src/components/__tests__/SegmentedButton.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { black } from '../../styles/themes/v2/colors'; @@ -13,46 +12,40 @@ import { } from '../SegmentedButtons/utils'; it('renders segmented button', () => { - const tree = renderer - .create( - {}} - value={'walk'} - buttons={[{ value: 'walk' }, { value: 'ride' }]} - /> - ) - .toJSON(); + const tree = render( + {}} + value={'walk'} + buttons={[{ value: 'walk' }, { value: 'ride' }]} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled segmented button', () => { - const tree = renderer - .create( - {}} - value={'walk'} - buttons={[{ value: 'walk' }, { value: 'ride', disabled: true }]} - /> - ) - .toJSON(); + const tree = render( + {}} + value={'walk'} + buttons={[{ value: 'walk' }, { value: 'ride', disabled: true }]} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders checked segmented button with selected check', () => { - const tree = renderer - .create( - {}} - value={'walk'} - buttons={[ - { value: 'walk', showSelectedCheck: true }, - { value: 'ride', disabled: true }, - ]} - /> - ) - .toJSON(); + const tree = render( + {}} + value={'walk'} + buttons={[ + { value: 'walk', showSelectedCheck: true }, + { value: 'ride', disabled: true }, + ]} + /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Snackbar.test.tsx b/src/components/__tests__/Snackbar.test.tsx index 41aec30f77..b9fcb31da4 100644 --- a/src/components/__tests__/Snackbar.test.tsx +++ b/src/components/__tests__/Snackbar.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { Animated, StyleSheet, Text, View } from 'react-native'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import { red200, white } from '../../styles/themes/v2/colors'; import Snackbar from '../Snackbar'; @@ -47,71 +46,61 @@ jest.mock('react-native-safe-area-context', () => ({ })); it('renders snackbar with content', () => { - const tree = renderer - .create( - - Snackbar content - - ) - .toJSON(); + const tree = render( + + Snackbar content + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders not visible snackbar with content wrapper but no actual content', () => { - const tree = renderer - .create( - - Snackbar content - - ) - .toJSON(); + const tree = render( + + Snackbar content + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders snackbar with Text as a child', () => { - const tree = renderer - .create( - - Snackbar content - - ) - .toJSON(); + const tree = render( + + Snackbar content + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders snackbar with action button', () => { - const tree = renderer - .create( - {}} - action={{ label: 'Undo', onPress: jest.fn() }} - > - Snackbar content - - ) - .toJSON(); + const tree = render( + {}} + action={{ label: 'Undo', onPress: jest.fn() }} + > + Snackbar content + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders snackbar with View & Text as a child', () => { - const tree = renderer - .create( - - - - - Error Message which is veryyyyyyyyyyyy longggggggg Error Message - which is veryyyyyyyyyyyy longggggggg - - - - ) - .toJSON(); + const tree = render( + + + + + Error Message which is veryyyyyyyyyyyy longggggggg Error Message which + is veryyyyyyyyyyyy longggggggg + + + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Switch.test.tsx b/src/components/__tests__/Switch.test.tsx index 2332d3cf26..e475b9a166 100644 --- a/src/components/__tests__/Switch.test.tsx +++ b/src/components/__tests__/Switch.test.tsx @@ -1,8 +1,8 @@ import * as React from 'react'; import { Platform } from 'react-native'; +import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { @@ -18,25 +18,25 @@ import Switch from '../Switch/Switch'; import { getSwitchColor } from '../Switch/utils'; it('renders on switch', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders off switch', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled switch', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); it('renders switch with color', () => { - const tree = renderer.create().toJSON(); + const tree = render().toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/ToggleButton.test.tsx b/src/components/__tests__/ToggleButton.test.tsx index e55ab7f239..83cd8e2659 100644 --- a/src/components/__tests__/ToggleButton.test.tsx +++ b/src/components/__tests__/ToggleButton.test.tsx @@ -3,7 +3,6 @@ import { Animated } from 'react-native'; import { render } from '@testing-library/react-native'; import color from 'color'; -import renderer from 'react-test-renderer'; import { getTheme } from '../../core/theming'; import { tokens } from '../../styles/themes/v3/tokens'; @@ -11,27 +10,25 @@ import ToggleButton from '../ToggleButton'; import { getToggleButtonColor } from '../ToggleButton/utils'; it('renders toggle button', () => { - const tree = renderer - .create( {}} icon="heart" />) - .toJSON(); + const tree = render( + {}} icon="heart" /> + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders disabled toggle button', () => { - const tree = renderer - .create( - - ) - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders unchecked toggle button', () => { - const tree = renderer - .create() - .toJSON(); + const tree = render( + + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Typography/Caption.test.tsx b/src/components/__tests__/Typography/Caption.test.tsx index 2a5480f353..b85bee50d4 100644 --- a/src/components/__tests__/Typography/Caption.test.tsx +++ b/src/components/__tests__/Typography/Caption.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; -import renderer from 'react-test-renderer'; +import { render } from '@testing-library/react-native'; import { red500 } from '../../../styles/themes/v2/colors'; import Caption from '../../Typography/v2/Caption'; @@ -14,15 +14,15 @@ const style = StyleSheet.create({ }); it('renders caption with children as content', () => { - const tree = renderer.create(Caption content).toJSON(); + const tree = render(Caption content).toJSON(); expect(tree).toMatchSnapshot(); }); it('renders caption applying style', () => { - const tree = renderer - .create(Big and red caption) - .toJSON(); + const tree = render( + Big and red caption + ).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/Typography/Text.test.tsx b/src/components/__tests__/Typography/Text.test.tsx index c349c4e8f2..19224ccda3 100644 --- a/src/components/__tests__/Typography/Text.test.tsx +++ b/src/components/__tests__/Typography/Text.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { render } from '@testing-library/react-native'; -import renderer from 'react-test-renderer'; import Provider from '../../../core/Provider'; import configureFonts from '../../../styles/fonts'; @@ -36,7 +35,7 @@ it('renders every variant of Text with children as content', () => { ); - const tree = renderer.create(variants).toJSON(); + const tree = render(variants).toJSON(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/__tests__/__snapshots__/Menu.test.tsx.snap b/src/components/__tests__/__snapshots__/Menu.test.tsx.snap index daa8f91b9c..dc24bab891 100644 --- a/src/components/__tests__/__snapshots__/Menu.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Menu.test.tsx.snap @@ -216,6 +216,7 @@ Array [ undefined, ] } + testID="menu-view" >