From ec032b0fc27c8e77fb27ab667d05eea1e22301ed Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 26 Apr 2024 22:55:47 +0200 Subject: [PATCH] fix: proper act usage (#1592) * fix: use proper act # Conflicts: # src/render-act.ts * fix: user event missing act on min press duration * chore: add button test * chore: spellcheck --- src/helpers/wrap-async.ts | 3 +-- src/render-act.ts | 3 ++- .../press/__tests__/press.real-timers.test.tsx | 4 ++-- src/user-event/press/__tests__/press.test.tsx | 14 ++++++++++++-- src/user-event/press/press.ts | 5 ++++- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/helpers/wrap-async.ts b/src/helpers/wrap-async.ts index 8efea896d..c22a1df5e 100644 --- a/src/helpers/wrap-async.ts +++ b/src/helpers/wrap-async.ts @@ -1,7 +1,6 @@ /* istanbul ignore file */ -import { act } from 'react-test-renderer'; -import { getIsReactActEnvironment, setReactActEnvironment } from '../act'; +import act, { getIsReactActEnvironment, setReactActEnvironment } from '../act'; import { flushMicroTasksLegacy } from '../flush-micro-tasks'; import { checkReactVersionAtLeast } from '../react-versions'; diff --git a/src/render-act.ts b/src/render-act.ts index 2b20fd654..50980562f 100644 --- a/src/render-act.ts +++ b/src/render-act.ts @@ -1,5 +1,6 @@ import TestRenderer from 'react-test-renderer'; import type { ReactTestRenderer, TestRendererOptions } from 'react-test-renderer'; +import act from './act'; export function renderWithAct( component: React.ReactElement, @@ -8,7 +9,7 @@ export function renderWithAct( let renderer: ReactTestRenderer; // This will be called synchronously. - void TestRenderer.act(() => { + void act(() => { renderer = TestRenderer.create(component, options); }); diff --git a/src/user-event/press/__tests__/press.real-timers.test.tsx b/src/user-event/press/__tests__/press.real-timers.test.tsx index 41b63c535..e0cca3346 100644 --- a/src/user-event/press/__tests__/press.real-timers.test.tsx +++ b/src/user-event/press/__tests__/press.real-timers.test.tsx @@ -203,7 +203,7 @@ describe('userEvent.press with real timers', () => { expect(getEventsName(events)).toEqual(['pressIn', 'press', 'pressOut']); }); - test('doesnt trigger on disabled Text', async () => { + test('does not trigger on disabled Text', async () => { const { events, logEvent } = createEventLogger(); render( @@ -222,7 +222,7 @@ describe('userEvent.press with real timers', () => { expect(events).toEqual([]); }); - test('doesnt trigger on Text with disabled pointer events', async () => { + test('does not trigger on Text with disabled pointer events', async () => { const { events, logEvent } = createEventLogger(); render( diff --git a/src/user-event/press/__tests__/press.test.tsx b/src/user-event/press/__tests__/press.test.tsx index 931ddcb77..5b2c95e53 100644 --- a/src/user-event/press/__tests__/press.test.tsx +++ b/src/user-event/press/__tests__/press.test.tsx @@ -6,6 +6,7 @@ import { TouchableHighlight, TouchableOpacity, View, + Button, } from 'react-native'; import { createEventLogger, getEventsName } from '../../../test-utils'; import { render, screen } from '../../..'; @@ -201,6 +202,15 @@ describe('userEvent.press with fake timers', () => { expect(getEventsName(events)).toEqual(['pressIn', 'press', 'pressOut']); }); + test('press works on Button', async () => { + const { events, logEvent } = createEventLogger(); + + render(