diff --git a/tests/basic.test.jsx b/tests/basic.test.jsx index aa4e87d..e5eb0aa 100644 --- a/tests/basic.test.jsx +++ b/tests/basic.test.jsx @@ -3,7 +3,7 @@ import { act, cleanup, fireEvent, render } from '@testing-library/react'; import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; import React, { StrictMode, createRef } from 'react'; -import ReactDOM from 'react-dom'; +import ReactDOM, { createPortal } from 'react-dom'; import Trigger from '../src'; import { awaitFakeTimer, placementAlignMap } from './util'; @@ -107,7 +107,7 @@ describe('Trigger.Basic', () => { expect(document.querySelector('.x-content').textContent).toBe('tooltip2'); trigger(container, '.target'); - expect(isPopupHidden).toBeTruthy(); + expect(isPopupHidden()).toBeTruthy(); }); it('click works with function', () => { @@ -1198,4 +1198,35 @@ describe('Trigger.Basic', () => { trigger(container, '.target'); expect(document.querySelector('.x-content').textContent).toBe('false'); }); + + it('createPortal should not close', async () => { + const Portal = () => + createPortal(
, document.body); + + const Demo = () => { + return ( + <> + }> +
+ +
+ + ); + }; + + const { container } = render(); + fireEvent.click(container.querySelector('.target')); + await awaitFakeTimer(); + expect(isPopupHidden()).toBeFalsy(); + + // Click portal should not close + fireEvent.click(document.querySelector('.portal')); + await awaitFakeTimer(); + expect(isPopupHidden()).toBeFalsy(); + + // Click outside to close + fireEvent.mouseDown(container.querySelector('.outer')); + await awaitFakeTimer(); + expect(isPopupHidden()).toBeTruthy(); + }); });