Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"typecheck": "tsc",
"lint": "eslint src --cache",
"validate": "yarn prettier && yarn lint && yarn typecheck && yarn test",
"validate:write": "yarn prettier:write && yarn lint --fix && yarn typecheck && yarn test -u",
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
"build:ts": "tsc --build tsconfig.release.json",
"build": "yarn clean && yarn build:js && yarn build:ts",
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/act.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ const Counter = () => {
return <Text onPress={() => setCount(count + 1)}>{text}</Text>;
};

test('render should trigger useEffect', () => {
test('render should trigger useEffect', async () => {
const effectCallback = jest.fn();
render(<UseEffect callback={effectCallback} />);
await render(<UseEffect callback={effectCallback} />);

expect(effectCallback).toHaveBeenCalledTimes(1);
});

test('rerender should trigger useEffect', () => {
test('rerender should trigger useEffect', async () => {
const effectCallback = jest.fn();
render(<UseEffect callback={effectCallback} />);
screen.rerender(<UseEffect callback={effectCallback} />);
await render(<UseEffect callback={effectCallback} />);
await screen.rerender(<UseEffect callback={effectCallback} />);

expect(effectCallback).toHaveBeenCalledTimes(2);
});

test('fireEvent should trigger useState', async () => {
render(<Counter />);
await render(<Counter />);
const counter = screen.getByText(/Total count/i);

expect(counter.props.children).toEqual('Total count: 0');
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/auto-cleanup-skip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Test extends React.Component<{ onUnmount?(): void }> {

// This just verifies that by importing RNTL in pure mode in an environment which supports
// afterEach (like jest) we won't get automatic cleanup between tests.
test('component is mounted, but not umounted before test ends', () => {
test('component is mounted, but not umounted before test ends', async () => {
const fn = jest.fn();
render(<Test onUnmount={fn} />);
await render(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();
});

Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/auto-cleanup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ afterEach(() => {

// This just verifies that by importing RNTL in an environment which supports afterEach (like jest)
// we'll get automatic cleanup between tests.
test('component is mounted, but not umounted before test ends', () => {
test('component is mounted, but not umounted before test ends', async () => {
const fn = jest.fn();
render(<Test onUnmount={fn} />);
await render(<Test onUnmount={fn} />);
expect(isMounted).toEqual(true);
expect(fn).not.toHaveBeenCalled();
});
Expand All @@ -38,14 +38,14 @@ test('component is automatically umounted after first test ends', () => {
expect(isMounted).toEqual(false);
});

test('does not time out with legacy fake timers', () => {
test('does not time out with legacy fake timers', async () => {
jest.useFakeTimers({ legacyFakeTimers: true });
render(<Test />);
await render(<Test />);
expect(isMounted).toEqual(true);
});

test('does not time out with fake timers', () => {
test('does not time out with fake timers', async () => {
jest.useFakeTimers();
render(<Test />);
await render(<Test />);
expect(isMounted).toEqual(true);
});
16 changes: 8 additions & 8 deletions src/__tests__/cleanup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { View } from 'react-native';

import { cleanupAsync, render, renderAsync } from '../pure';
import { cleanup, render, unsafe_renderSync } from '../pure';

class Test extends React.Component<{ onUnmount: () => void }> {
componentWillUnmount() {
Expand All @@ -17,21 +17,21 @@ class Test extends React.Component<{ onUnmount: () => void }> {
test('cleanup after render', async () => {
const fn = jest.fn();

render(<Test onUnmount={fn} />);
render(<Test onUnmount={fn} />);
await render(<Test onUnmount={fn} />);
await render(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();

await cleanupAsync();
await cleanup();
expect(fn).toHaveBeenCalledTimes(2);
});

test('cleanup after renderAsync', async () => {
test('cleanup after unsafe_renderSync', async () => {
const fn = jest.fn();

await renderAsync(<Test onUnmount={fn} />);
await renderAsync(<Test onUnmount={fn} />);
unsafe_renderSync(<Test onUnmount={fn} />);
unsafe_renderSync(<Test onUnmount={fn} />);
expect(fn).not.toHaveBeenCalled();

await cleanupAsync();
await cleanup();
expect(fn).toHaveBeenCalledTimes(2);
});
8 changes: 4 additions & 4 deletions src/__tests__/event-handler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Text, View } from 'react-native';
import { render, screen } from '..';
import { getEventHandlerFromProps } from '../event-handler';

test('getEventHandler strict mode', () => {
test('getEventHandler strict mode', async () => {
const onPress = jest.fn();
const testOnlyOnPress = jest.fn();

render(
await render(
<View>
<Text testID="regular" onPress={onPress} />
{/* @ts-expect-error Intentionally passing such props */}
Expand All @@ -31,11 +31,11 @@ test('getEventHandler strict mode', () => {
expect(getEventHandlerFromProps(both.props, 'onPress')).toBe(undefined);
});

test('getEventHandler loose mode', () => {
test('getEventHandler loose mode', async () => {
const onPress = jest.fn();
const testOnlyOnPress = jest.fn();

render(
await render(
<View>
<Text testID="regular" onPress={onPress} />
{/* @ts-expect-error Intentionally passing such props */}
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/fire-event-textInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('should fire only non-touch-related events on non-editable TextInput', asyn
const onSubmitEditing = jest.fn();
const onLayout = jest.fn();

render(
await render(
<TextInput
editable={false}
testID="subject"
Expand Down Expand Up @@ -49,7 +49,7 @@ test('should fire only non-touch-related events on non-editable TextInput with n
const onSubmitEditing = jest.fn();
const onLayout = jest.fn();

render(
await render(
<TextInput
editable={false}
testID="subject"
Expand Down Expand Up @@ -100,7 +100,7 @@ test('should fire only non-touch-related events on non-editable wrapped TextInpu
const onSubmitEditing = jest.fn();
const onLayout = jest.fn();

render(
await render(
<WrappedTextInput
editable={false}
testID="subject"
Expand Down Expand Up @@ -132,7 +132,7 @@ test('should fire only non-touch-related events on non-editable double wrapped T
const onSubmitEditing = jest.fn();
const onLayout = jest.fn();

render(
await render(
<DoubleWrappedTextInput
editable={false}
testID="subject"
Expand Down
Loading