Skip to content

Commit

Permalink
Rename to dispatchAndWaitForDiscrete.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jan 25, 2024
1 parent c646280 commit 2ae431c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/internal-test-utils/ReactInternalTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ${diff(expectedLog, actualLog)}
// Simulates dispatching events, waiting for microtasks in between.
// This matches the browser behavior, which will flush microtasks
// between each event handler.
export async function waitForEvents(
export async function dispatchAndWaitForDiscrete(
node: Node,
eventType: string,
): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ let React;
let act;
let Scheduler;
let ReactDOMClient;
let waitForEvents;
let dispatchAndWaitForDiscrete;
let assertLog;

describe('ReactInternalTestUtilsDOM', () => {
beforeEach(() => {
jest.resetModules();
act = require('internal-test-utils').act;
waitForEvents = require('internal-test-utils').waitForEvents;
dispatchAndWaitForDiscrete =
require('internal-test-utils').dispatchAndWaitForDiscrete;
Scheduler = require('scheduler/unstable_mock');
ReactDOMClient = require('react-dom/client');
React = require('react');
assertLog = require('internal-test-utils').assertLog;
});
describe('waitForEvents', () => {
describe('dispatchAndWaitForDiscrete', () => {
test('should fire capture events (discrete)', async () => {
let childRef;
function Component() {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('ReactInternalTestUtilsDOM', () => {
assertLog(['Render 0']);

await act(async () => {
await waitForEvents(childRef, 'click');
await dispatchAndWaitForDiscrete(childRef, 'click');
});

// Capture runs on every event we dispatch,
Expand Down Expand Up @@ -110,7 +111,7 @@ describe('ReactInternalTestUtilsDOM', () => {
assertLog(['Render 0']);

await act(async () => {
await waitForEvents(childRef, 'click');
await dispatchAndWaitForDiscrete(childRef, 'click');
});

assertLog(['onClick child', 'onClick parent', 'Render 1']);
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('ReactInternalTestUtilsDOM', () => {
assertLog(['Render 0']);

await act(async () => {
await waitForEvents(childRef, 'mouseout');
await dispatchAndWaitForDiscrete(childRef, 'mouseout');
});

// Capture runs on every event we dispatch,
Expand Down Expand Up @@ -198,7 +199,7 @@ describe('ReactInternalTestUtilsDOM', () => {
assertLog(['Render 0']);

await act(async () => {
await waitForEvents(childRef, 'mouseout');
await dispatchAndWaitForDiscrete(childRef, 'mouseout');
});

assertLog(['onMouseOut child', 'onMouseOut parent', 'Render 1']);
Expand Down
11 changes: 6 additions & 5 deletions packages/react-dom/src/__tests__/ReactDOMEventListener-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

'use strict';

import {enableLegacyFBSupport} from 'shared/forks/ReactFeatureFlags.www-dynamic';
import {dispatchAndWaitForDiscrete} from 'internal-test-utils';

describe('ReactDOMEventListener', () => {
let React;
let ReactDOM;
let ReactDOMClient;
let ReactDOMServer;
let act;
let waitForEvents;
let dispatchAndWaitForDiscrete;

beforeEach(() => {
jest.resetModules();
Expand All @@ -26,7 +26,8 @@ describe('ReactDOMEventListener', () => {
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
act = require('internal-test-utils').act;
waitForEvents = require('internal-test-utils').waitForEvents;
dispatchAndWaitForDiscrete =
require('internal-test-utils').dispatchAndWaitForDiscrete;
});

describe('Propagation', () => {
Expand Down Expand Up @@ -190,7 +191,7 @@ describe('ReactDOMEventListener', () => {

try {
await act(async () => {
await waitForEvents(childNode, 'click');
await dispatchAndWaitForDiscrete(childNode, 'click');
});

// Child and parent should both call from event handlers.
Expand Down Expand Up @@ -270,7 +271,7 @@ describe('ReactDOMEventListener', () => {

try {
await act(async () => {
await waitForEvents(childNode, 'mouseout');
await dispatchAndWaitForDiscrete(childNode, 'mouseout');
});

// Child and parent should both call from event handlers.
Expand Down

0 comments on commit 2ae431c

Please sign in to comment.