Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
test: add test case
  • Loading branch information
zombieJ committed Sep 15, 2025
commit b2341f11b9bfb3bee15aa75807b52537b222bffb
28 changes: 28 additions & 0 deletions tests/unique.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@ import React from 'react';
import Trigger, { UniqueProvider } from '../src';
import { awaitFakeTimer } from './util';

// Mock FloatBg to check if open props changed
global.openChangeLog = [];

jest.mock('../src/UniqueProvider/FloatBg', () => {
const OriginalFloatBg = jest.requireActual(
'../src/UniqueProvider/FloatBg',
).default;
const OriginReact = jest.requireActual('react');

return (props: any) => {
const { open } = props;
const openRef = OriginReact.useRef(open);

OriginReact.useEffect(() => {
if (openRef.current !== open) {
global.openChangeLog.push({ from: openRef.current, to: open });
openRef.current = open;
}
}, [open]);

return OriginReact.createElement(OriginalFloatBg, props);
};
});

describe('Trigger.Unique', () => {
beforeEach(() => {
jest.useFakeTimers();
global.openChangeLog = [];
});

afterEach(() => {
Expand Down Expand Up @@ -74,5 +99,8 @@ describe('Trigger.Unique', () => {
expect(document.querySelectorAll('.rc-trigger-popup-float-bg').length).toBe(
1,
);

// FloatBg open prop should not have changed during transition (no close animation)
expect(global.openChangeLog).toHaveLength(0);
});
});
Loading