refactor: centralize renderer selection

This commit is contained in:
Maciej Jastrzebski
2024-09-16 16:16:40 +02:00
parent e5eb0c318c
commit ea795badd8
21 changed files with 22 additions and 97 deletions
+1 -5
View File
@@ -1,10 +1,6 @@
import * as React from 'react';
import { View } from 'react-native';
import { configure, render } from '..';
beforeEach(() => {
configure({ renderer: 'internal' });
});
import { render } from '..';
let isMounted = false;
+1 -5
View File
@@ -1,7 +1,7 @@
import * as React from 'react';
import { View } from 'react-native';
import TestRenderer from 'react-test-renderer';
import { configure, configureInternal, getConfig } from '../config';
import { configureInternal, getConfig } from '../config';
import {
getHostComponentNames,
configureHostComponentNamesIfNeeded,
@@ -9,10 +9,6 @@ import {
import { act, render } from '..';
import * as internalRenderer from '../renderer/renderer';
beforeEach(() => {
configure({ renderer: 'internal' });
});
describe('getHostComponentNames', () => {
test('returns host component names from internal config', () => {
configureInternal({
+1 -5
View File
@@ -1,10 +1,6 @@
import * as React from 'react';
import { View, Text } from 'react-native';
import { configure, render, screen } from '..';
beforeEach(() => {
configure({ renderer: 'internal' });
});
import { render, screen } from '..';
test('screen has the same queries as render result', () => {
const result = render(<Text>Mt. Everest</Text>);
@@ -2,11 +2,7 @@ import * as React from 'react';
import { View } from 'react-native';
// Note: that must point to root of the /src to reliably replicate default import.
import { configure, render } from '../..';
beforeEach(() => {
configure({ renderer: 'internal' });
});
import { render } from '../..';
// This is check that RNTL does not extend "expect" by default, until we actually want to expose Jest matchers publically.
test('does not extend "expect" by default', () => {
+1 -5
View File
@@ -1,12 +1,8 @@
import * as React from 'react';
import { View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('toBeBusy() basic case', () => {
render(
<>
@@ -1,12 +1,8 @@
import React from 'react';
import { type AccessibilityRole, Switch, View } from 'react-native';
import { render, screen, configure } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
function renderViewsWithRole(role: AccessibilityRole) {
render(
<>
@@ -10,13 +10,9 @@ import {
Text,
View,
} from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
// beforeEach(() => {
// configure({ renderer: 'internal' });
// });
test('toBeDisabled()/toBeEnabled() supports basic case', () => {
render(
<View>
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -9,10 +9,6 @@ function DoNotRenderChildren({ children }: { children: React.ReactNode }) {
return null;
}
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('toBeEmptyElement() base case', () => {
render(
<View testID="not-empty">
@@ -1,12 +1,8 @@
import * as React from 'react';
import { View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('toBeExpanded() basic case', () => {
render(
<>
@@ -1,12 +1,8 @@
import * as React from 'react';
import { View, Text } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('toBeOnTheScreen() example test', () => {
render(
<View>
@@ -1,12 +1,8 @@
import * as React from 'react';
import { TextInput, View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
import '../extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('toHaveDisplayValue() example test', () => {
render(<TextInput testID="text-input" value="test" />);
@@ -1,12 +1,11 @@
/* eslint-disable no-console */
import * as React from 'react';
import { View, Text, Pressable, TouchableOpacity } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
type ConsoleLogMock = jest.Mock<typeof console.log>;
beforeEach(() => {
configure({ renderer: 'internal' });
jest.spyOn(console, 'warn').mockImplementation(() => {});
});
@@ -1,12 +1,11 @@
/* eslint-disable no-console */
import * as React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
type ConsoleLogMock = jest.Mock<typeof console.log>;
beforeEach(() => {
configure({ renderer: 'internal' });
jest.spyOn(console, 'warn').mockImplementation(() => {});
});
+1 -5
View File
@@ -1,12 +1,8 @@
import * as React from 'react';
import { TextInput, View } from 'react-native';
import { configure, fireEvent, render, screen } from '../..';
import { fireEvent, render, screen } from '../..';
import '../../matchers/extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
});
const PLACEHOLDER_FRESHNESS = 'Add custom freshness';
const PLACEHOLDER_CHEF = 'Who inspected freshness?';
const INPUT_FRESHNESS = 'Custom Freshie';
@@ -1,6 +1,6 @@
import * as React from 'react';
import { TextInput, View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
const PLACEHOLDER_FRESHNESS = 'Add custom freshness';
const PLACEHOLDER_CHEF = 'Who inspected freshness?';
@@ -24,10 +24,6 @@ const Banana = () => (
</View>
);
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('getByPlaceholderText, queryByPlaceholderText', () => {
render(<Banana />);
const input = screen.getByPlaceholderText(/custom/i);
+1 -5
View File
@@ -10,7 +10,7 @@ import {
View,
Switch,
} from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
const TEXT_LABEL = 'cool text';
@@ -42,10 +42,6 @@ const Section = () => (
</>
);
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('getByRole, queryByRole, findByRole', async () => {
render(<Section />);
+1 -5
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { Button, Text, TextInput, View } from 'react-native';
import { configure, render, screen } from '../..';
import { render, screen } from '../..';
const PLACEHOLDER_FRESHNESS = 'Add custom freshness';
const PLACEHOLDER_CHEF = 'Who inspected freshness?';
@@ -24,10 +24,6 @@ const Banana = () => (
const MyComponent = (_props: { testID?: string }) => <Text>My Component</Text>;
beforeEach(() => {
configure({ renderer: 'internal' });
});
test('getByTestId returns only native elements', () => {
render(
<View>
+2 -6
View File
@@ -1,10 +1,6 @@
import * as React from 'react';
import { Button, Image, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { configure, getDefaultNormalizer, render, screen, within } from '../..';
beforeEach(() => {
configure({ renderer: 'internal' });
});
import { getDefaultNormalizer, render, screen, within } from '../..';
test('byText matches simple text', () => {
render(<Text testID="text">Hello World</Text>);
@@ -20,7 +16,7 @@ test('byText matches inner nested text', () => {
expect(screen.getByText('Hello World').props.testID).toBe('inner');
});
test('byText matches accross multiple texts', () => {
test('byText matches across multiple texts', () => {
render(
<Text testID="outer">
<Text testID="inner-1">Hello</Text> <Text testID="inner-2">World</Text>
@@ -8,13 +8,9 @@ import {
View,
} from 'react-native';
import { createEventLogger, getEventsNames } from '../../../test-utils';
import { configure, render, screen } from '../../..';
import { render, screen } from '../../..';
import { userEvent } from '../..';
// beforeEach(() => {
// configure({ renderer: 'internal' });
// });
describe('userEvent.press with real timers', () => {
beforeEach(() => {
jest.useRealTimers();
@@ -9,13 +9,9 @@ import {
Button,
} from 'react-native';
import { createEventLogger, getEventsNames } from '../../../test-utils';
import { configure, render, screen } from '../../..';
import { render, screen } from '../../..';
import { userEvent } from '../..';
// beforeEach(() => {
// configure({ renderer: 'internal' });
// });
describe('userEvent.press with fake timers', () => {
beforeEach(() => {
jest.useFakeTimers();
+1 -2
View File
@@ -1,12 +1,11 @@
import * as React from 'react';
import { TextInput, TextInputProps, View } from 'react-native';
import { createEventLogger, getEventsNames, lastEventPayload } from '../../../test-utils';
import { configure, render, screen } from '../../..';
import { render, screen } from '../../..';
import { userEvent } from '../..';
import '../../../matchers/extend-expect';
beforeEach(() => {
configure({ renderer: 'internal' });
jest.useRealTimers();
});