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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe('SimpleEventPlugin', function () {

let onClick;
let container;
let assertLog;
let waitForAll;

function expectClickThru(element) {
element.click();
Expand All @@ -43,6 +45,10 @@ describe('SimpleEventPlugin', function () {
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
waitForAll = InternalTestUtils.waitForAll;

onClick = jest.fn();
});

Expand Down Expand Up @@ -222,12 +228,12 @@ describe('SimpleEventPlugin', function () {

ReactDOM.render(<Button />, container);
expect(button.textContent).toEqual('Count: 0');
expect(Scheduler).toHaveYielded([]);
assertLog([]);

click();

// There should be exactly one update.
expect(Scheduler).toHaveYielded(['didUpdate - Count: 3']);
assertLog(['didUpdate - Count: 3']);
expect(button.textContent).toEqual('Count: 3');
});

Expand All @@ -240,6 +246,10 @@ describe('SimpleEventPlugin', function () {
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
waitForAll = InternalTestUtils.waitForAll;

act = require('jest-react').act;
});

Expand Down Expand Up @@ -274,10 +284,10 @@ describe('SimpleEventPlugin', function () {
// Initial mount
root.render(<Button />);
// Should not have flushed yet because it's async
expect(Scheduler).toHaveYielded([]);
assertLog([]);
expect(button).toBe(undefined);
// Flush async work
expect(Scheduler).toFlushAndYield(['render button: enabled']);
await waitForAll(['render button: enabled']);

function click() {
const event = new MouseEvent('click', {
Expand All @@ -292,7 +302,7 @@ describe('SimpleEventPlugin', function () {

// Click the button to trigger the side-effect
await act(async () => click());
expect(Scheduler).toHaveYielded([
assertLog([
// The handler fired
'Side-effect',
// The component re-rendered synchronously, even in concurrent mode.
Expand All @@ -301,7 +311,7 @@ describe('SimpleEventPlugin', function () {

// Click the button again
click();
expect(Scheduler).toHaveYielded([
assertLog([
// The event handler was removed from the button, so there's no effect.
]);

Expand All @@ -312,7 +322,7 @@ describe('SimpleEventPlugin', function () {
click();
click();
click();
expect(Scheduler).toFlushAndYield([]);
await waitForAll([]);
});

// NOTE: This test was written for the old behavior of discrete updates,
Expand Down Expand Up @@ -345,7 +355,7 @@ describe('SimpleEventPlugin', function () {
// Should not have flushed yet because it's async
expect(button).toBe(undefined);
// Flush async work
Scheduler.unstable_flushAll();
await waitForAll([]);
expect(button.textContent).toEqual('Count: 0');

function click() {
Expand Down Expand Up @@ -373,7 +383,7 @@ describe('SimpleEventPlugin', function () {
await act(async () => click());

// Flush the remaining work
Scheduler.unstable_flushAll();
await waitForAll([]);
// The counter should equal the total number of clicks
expect(button.textContent).toEqual('Count: 7');
});
Expand Down
Loading