Skip to content

Commit b2341f1

Browse files
committed
test: add test case
1 parent 3007967 commit b2341f1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unique.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@ import React from 'react';
33
import Trigger, { UniqueProvider } from '../src';
44
import { awaitFakeTimer } from './util';
55

6+
// Mock FloatBg to check if open props changed
7+
global.openChangeLog = [];
8+
9+
jest.mock('../src/UniqueProvider/FloatBg', () => {
10+
const OriginalFloatBg = jest.requireActual(
11+
'../src/UniqueProvider/FloatBg',
12+
).default;
13+
const OriginReact = jest.requireActual('react');
14+
15+
return (props: any) => {
16+
const { open } = props;
17+
const openRef = OriginReact.useRef(open);
18+
19+
OriginReact.useEffect(() => {
20+
if (openRef.current !== open) {
21+
global.openChangeLog.push({ from: openRef.current, to: open });
22+
openRef.current = open;
23+
}
24+
}, [open]);
25+
26+
return OriginReact.createElement(OriginalFloatBg, props);
27+
};
28+
});
29+
630
describe('Trigger.Unique', () => {
731
beforeEach(() => {
832
jest.useFakeTimers();
33+
global.openChangeLog = [];
934
});
1035

1136
afterEach(() => {
@@ -74,5 +99,8 @@ describe('Trigger.Unique', () => {
7499
expect(document.querySelectorAll('.rc-trigger-popup-float-bg').length).toBe(
75100
1,
76101
);
102+
103+
// FloatBg open prop should not have changed during transition (no close animation)
104+
expect(global.openChangeLog).toHaveLength(0);
77105
});
78106
});

0 commit comments

Comments
 (0)