Skip to content

Commit 9030154

Browse files
committed
test: add test case
1 parent c779293 commit 9030154

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tests/basic.test.jsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { act, cleanup, fireEvent, render } from '@testing-library/react';
44
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
55
import React, { StrictMode, createRef } from 'react';
6-
import ReactDOM from 'react-dom';
6+
import ReactDOM, { createPortal } from 'react-dom';
77
import Trigger from '../src';
88
import { awaitFakeTimer, placementAlignMap } from './util';
99

@@ -107,7 +107,7 @@ describe('Trigger.Basic', () => {
107107
expect(document.querySelector('.x-content').textContent).toBe('tooltip2');
108108

109109
trigger(container, '.target');
110-
expect(isPopupHidden).toBeTruthy();
110+
expect(isPopupHidden()).toBeTruthy();
111111
});
112112

113113
it('click works with function', () => {
@@ -1198,4 +1198,35 @@ describe('Trigger.Basic', () => {
11981198
trigger(container, '.target');
11991199
expect(document.querySelector('.x-content').textContent).toBe('false');
12001200
});
1201+
1202+
it('createPortal should not close', async () => {
1203+
const Portal = () =>
1204+
createPortal(<div className="portal" />, document.body);
1205+
1206+
const Demo = () => {
1207+
return (
1208+
<>
1209+
<Trigger action="click" popup={<Portal />}>
1210+
<div className="target" />
1211+
</Trigger>
1212+
<div className="outer" />
1213+
</>
1214+
);
1215+
};
1216+
1217+
const { container } = render(<Demo />);
1218+
fireEvent.click(container.querySelector('.target'));
1219+
await awaitFakeTimer();
1220+
expect(isPopupHidden()).toBeFalsy();
1221+
1222+
// Click portal should not close
1223+
fireEvent.click(document.querySelector('.portal'));
1224+
await awaitFakeTimer();
1225+
expect(isPopupHidden()).toBeFalsy();
1226+
1227+
// Click outside to close
1228+
fireEvent.mouseDown(container.querySelector('.outer'));
1229+
await awaitFakeTimer();
1230+
expect(isPopupHidden()).toBeTruthy();
1231+
});
12011232
});

0 commit comments

Comments
 (0)