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