Skip to content

Commit

Permalink
Asyncify ReactNativeTestTools.expectRendersMatchingSnapshot
Browse files Browse the repository at this point in the history
Summary:
To allow for async `act` in a subsequent diff, make this utility method async and awaited at all call sites.

Changelog: [Internal]

Differential Revision: D58647828
  • Loading branch information
robhogan authored and facebook-github-bot committed Jun 16, 2024
1 parent 47522ae commit 9087e1a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" />,
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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}>
Expand All @@ -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={{}}>
Expand All @@ -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}}>
Expand All @@ -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}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} />,
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('ScrollView', () => {
jest.resetModules();
});

it('renders its children', () => {
ReactNativeTestTools.expectRendersMatchingSnapshot(
it('renders its children', async () => {
await ReactNativeTestTools.expectRendersMatchingSnapshot(
'ScrollView',
() => (
<ScrollView>
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -192,8 +201,8 @@ describe('TextInput tests', () => {
`);
});

it('should render as expected', () => {
expectRendersMatchingSnapshot(
it('should render as expected', async () => {
await expectRendersMatchingSnapshot(
'TextInput',
() => <TextInput />,
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function expectNoConsoleError() {
});
}

function expectRendersMatchingSnapshot(
async function expectRendersMatchingSnapshot(
name: string,
ComponentProvider: () => React.Element<any>,
unmockComponent: () => mixed,
Expand Down

0 comments on commit 9087e1a

Please sign in to comment.