Asyncify ReactNativeTestTools.expectRendersMatchingSnapshot (#44992)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44992

To allow for async `act` in a subsequent diff, make this utility method async and awaited at all call sites.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D58647828

fbshipit-source-id: 3a47c57569814638c216309eed1885dd37521dde
This commit is contained in:
Rob Hogan
2024-06-16 16:55:21 -07:00
committed by Facebook GitHub Bot
parent 1e11257670
commit 910e7133bc
8 changed files with 33 additions and 24 deletions
@@ -21,8 +21,8 @@ describe('<ActivityIndicator />', () => {
expect(ActivityIndicator.displayName).toBe('ActivityIndicator');
});
it('should render as expected', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'ActivityIndicator',
() => <ActivityIndicator size="large" color="#0000ff" />,
() => {
@@ -21,8 +21,8 @@ const DrawerLayoutAndroid = require('../DrawerLayoutAndroid.android');
const React = require('react');
describe('<DrawerLayoutAndroid />', () => {
it('should render as expected', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'DrawerLayoutAndroid',
() => (
<DrawerLayoutAndroid
@@ -15,8 +15,8 @@ import Pressable from '../Pressable';
import * as React from 'react';
describe('<Pressable />', () => {
it('should render as expected', () => {
expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable>
@@ -31,8 +31,8 @@ describe('<Pressable />', () => {
});
describe('<Pressable disabled={true} />', () => {
it('should be disabled when disabled is true', () => {
expectRendersMatchingSnapshot(
it('should be disabled when disabled is true', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable disabled={true}>
@@ -47,8 +47,8 @@ describe('<Pressable disabled={true} />', () => {
});
describe('<Pressable disabled={true} accessibilityState={{}} />', () => {
it('should be disabled when disabled is true and accessibilityState is empty', () => {
expectRendersMatchingSnapshot(
it('should be disabled when disabled is true and accessibilityState is empty', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable disabled={true} accessibilityState={{}}>
@@ -63,8 +63,8 @@ describe('<Pressable disabled={true} accessibilityState={{}} />', () => {
});
describe('<Pressable disabled={true} accessibilityState={{checked: true}} />', () => {
it('should keep accessibilityState when disabled is true', () => {
expectRendersMatchingSnapshot(
it('should keep accessibilityState when disabled is true', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable disabled={true} accessibilityState={{checked: true}}>
@@ -79,8 +79,8 @@ describe('<Pressable disabled={true} accessibilityState={{checked: true}} />', (
});
describe('<Pressable disabled={true} accessibilityState={{disabled: false}} />', () => {
it('should overwrite accessibilityState with value of disabled prop', () => {
expectRendersMatchingSnapshot(
it('should overwrite accessibilityState with value of disabled prop', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable disabled={true} accessibilityState={{disabled: false}}>
@@ -20,8 +20,8 @@ const ProgressBarAndroid = require('../ProgressBarAndroid.android');
const React = require('react');
describe('<ProgressBarAndroid />', () => {
it('should render as expected', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'ProgressBarAndroid',
() => <ProgressBarAndroid styleAttr="Horizontal" indeterminate={true} />,
() => {
@@ -19,8 +19,8 @@ const View = require('../../View/View');
const React = require('react');
describe('<SafeAreaView />', () => {
it('should render as expected', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'SafeAreaView',
() => (
<SafeAreaView>
@@ -23,8 +23,8 @@ describe('ScrollView', () => {
jest.resetModules();
});
it('renders its children', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('renders its children', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'ScrollView',
() => (
<ScrollView>
@@ -1,3 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const ReactNative = require('../../../ReactNative/RendererProxy');
const {
enter,
@@ -40,7 +49,7 @@ describe('TextInput tests', () => {
input = renderTree.root.findByType(TextInput);
});
it('has expected instance functions', () => {
expect(inputRef.current.isFocused).toBeInstanceOf(Function); // Would have prevented S168585
expect(inputRef.current.isFocused).toBeInstanceOf(Function); // Would have prevented S168585
expect(inputRef.current.clear).toBeInstanceOf(Function);
expect(inputRef.current.focus).toBeInstanceOf(jest.fn().constructor);
expect(inputRef.current.blur).toBeInstanceOf(jest.fn().constructor);
@@ -192,8 +201,8 @@ describe('TextInput tests', () => {
`);
});
it('should render as expected', () => {
expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await expectRendersMatchingSnapshot(
'TextInput',
() => <TextInput />,
() => {
@@ -113,7 +113,7 @@ function expectNoConsoleError() {
});
}
function expectRendersMatchingSnapshot(
async function expectRendersMatchingSnapshot(
name: string,
ComponentProvider: () => React.Element<any>,
unmockComponent: () => mixed,