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
11 changes: 2 additions & 9 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -92,17 +92,10 @@ describe('ReactFlight', () => {
beforeEach(() => {
// Mock performance.now for timing tests
let time = 10;
const now = jest.fn().mockImplementation(() => {
jest.spyOn(performance, 'timeOrigin', 'get').mockReturnValue(time);
jest.spyOn(performance, 'now').mockImplementation(() => {
return time++;
});
Object.defineProperty(performance, 'timeOrigin', {
value: time,
configurable: true,
});
Object.defineProperty(performance, 'now', {
value: now,
configurable: true,
});

jest.resetModules();
jest.mock('react', () => require('react/react.react-server'));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,17 +29,10 @@ describe('ReactFlight', () => {
beforeEach(() => {
// Mock performance.now for timing tests
let time = 10;
const now = jest.fn().mockImplementation(() => {
jest.spyOn(performance, 'timeOrigin', 'get').mockReturnValue(time);
jest.spyOn(performance, 'now').mockImplementation(() => {
return time++;
});
Object.defineProperty(performance, 'timeOrigin', {
value: time,
configurable: true,
});
Object.defineProperty(performance, 'now', {
value: now,
configurable: true,
});

jest.resetModules();
jest.mock('react', () => require('react/react.react-server'));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3152,7 +3152,7 @@ function normalizeListenerOptions(
opts: ?EventListenerOptionsOrUseCapture,
): string {
if (opts == null) {
return '0';
return 'c=0';
}

if (typeof opts === 'boolean') {
Expand Down
41 changes: 41 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFragmentRefs-test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -832,6 +832,47 @@ describe('FragmentRefs', () => {
expect(logs).toEqual([]);
});

// @gate enableFragmentRefs
it('matches listeners by their normalized capture flag', async () => {
const fragmentRef = React.createRef();
const childRef = React.createRef();
const root = ReactDOMClient.createRoot(container);
const logs = [];

function addedWithOmittedOptions() {
logs.push('addedWithOmittedOptions');
}

function addedWithCaptureFalse() {
logs.push('addedWithCaptureFalse');
}

await act(() => {
root.render(
<Fragment ref={fragmentRef}>
<div ref={childRef}>child</div>
</Fragment>,
);
});

fragmentRef.current.addEventListener('click', addedWithOmittedOptions);
fragmentRef.current.addEventListener('click', addedWithCaptureFalse, {
capture: false,
});

// Omitted options and an explicit capture: false are the same
// EventTarget listener identity, so each removal should match.
fragmentRef.current.removeEventListener(
'click',
addedWithOmittedOptions,
false,
);
fragmentRef.current.removeEventListener('click', addedWithCaptureFalse);

childRef.current.click();
expect(logs).toEqual([]);
});

// @gate enableFragmentRefs
it('adds and removes event listeners from children with multiple fragments', async () => {
const fragmentRef = React.createRef();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,17 +27,10 @@ describe('ReactOwnerStacks', () => {
time += timeMS;
};

const now = jest.fn().mockImplementation(() => {
jest.spyOn(performance, 'timeOrigin', 'get').mockReturnValue(time);
jest.spyOn(performance, 'now').mockImplementation(() => {
return time++;
});
Object.defineProperty(performance, 'timeOrigin', {
value: time,
configurable: true,
});
Object.defineProperty(performance, 'now', {
value: now,
configurable: true,
});

jest.resetModules();
React = require('react');
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,18 +19,17 @@ describe('ReactPerformanceTracks', () => {

beforeEach(() => {
performanceMeasureCalls.length = 0;
Object.defineProperty(performance, 'measure', {
value: jest.fn((measureName, reusableOptions) => {
jest
.spyOn(performance, 'measure')
.mockImplementation((measureName, reusableOptions) => {
performanceMeasureCalls.push([
measureName,
{
// React will mutate the options it passes to performance.measure.
...reusableOptions,
},
]);
}),
configurable: true,
});
});
console.timeStamp = () => {};
jest.spyOn(console, 'timeStamp').mockImplementation(() => {});

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,17 +47,10 @@ describe('ReactFlightDOMEdge', () => {
beforeEach(() => {
// Mock performance.now for timing tests
let time = 10;
const now = jest.fn().mockImplementation(() => {
jest.spyOn(performance, 'timeOrigin', 'get').mockReturnValue(time);
jest.spyOn(performance, 'now').mockImplementation(() => {
return time++;
});
Object.defineProperty(performance, 'timeOrigin', {
value: time,
configurable: true,
});
Object.defineProperty(performance, 'now', {
value: now,
configurable: true,
});

jest.resetModules();

Expand Down
11 changes: 2 additions & 9 deletions packages/react-server/src/__tests__/ReactFlightServer-test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,17 +46,10 @@ describe('ReactFlight', () => {
time += timeMS;
jest.advanceTimersByTime(timeMS);
};
const now = jest.fn().mockImplementation(() => {
jest.spyOn(performance, 'timeOrigin', 'get').mockReturnValue(time);
jest.spyOn(performance, 'now').mockImplementation(() => {
return time++;
});
Object.defineProperty(performance, 'timeOrigin', {
value: time,
configurable: true,
});
Object.defineProperty(performance, 'now', {
value: now,
configurable: true,
});

jest.resetModules();
jest.mock('react', () => require('react/react.react-server'));
Expand Down
Loading