2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2020-04-29 20:22:16 +08:00
|
|
|
import ConfigProvider from '..';
|
2023-06-07 11:54:50 +08:00
|
|
|
import { act, render } from '../../../tests/utils';
|
2020-04-29 20:22:16 +08:00
|
|
|
import Affix from '../../affix';
|
|
|
|
import Anchor from '../../anchor';
|
|
|
|
|
|
|
|
describe('ConfigProvider.getTargetContainer', () => {
|
|
|
|
it('Affix', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
|
|
|
const getTargetContainer = jest.fn(() => window);
|
2022-08-22 22:54:38 +08:00
|
|
|
render(
|
2020-04-29 20:22:16 +08:00
|
|
|
<ConfigProvider getTargetContainer={getTargetContainer}>
|
|
|
|
<Affix>
|
|
|
|
<span />
|
|
|
|
</Affix>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2022-08-08 13:31:55 +08:00
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2022-08-08 13:31:55 +08:00
|
|
|
});
|
2020-04-29 20:22:16 +08:00
|
|
|
|
|
|
|
expect(getTargetContainer).toHaveBeenCalled();
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useRealTimers();
|
2020-04-29 20:22:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Anchor', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
|
|
|
const getTargetContainer = jest.fn(() => window);
|
2022-08-22 22:54:38 +08:00
|
|
|
render(
|
2020-04-29 20:22:16 +08:00
|
|
|
<ConfigProvider getTargetContainer={getTargetContainer}>
|
|
|
|
<Anchor>
|
|
|
|
<Anchor.Link href="#API" title="API" />
|
|
|
|
</Anchor>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2022-08-08 13:31:55 +08:00
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2022-08-08 13:31:55 +08:00
|
|
|
});
|
2020-04-29 20:22:16 +08:00
|
|
|
|
|
|
|
expect(getTargetContainer).toHaveBeenCalled();
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useRealTimers();
|
2020-04-29 20:22:16 +08:00
|
|
|
});
|
|
|
|
});
|