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';
|
|
|
|
|
|
|
|
describe('ConfigProvider.getTargetContainer', () => {
|
|
|
|
it('Affix', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const getTargetContainer = jest.fn(() => window);
|
|
|
|
mount(
|
|
|
|
<ConfigProvider getTargetContainer={getTargetContainer}>
|
|
|
|
<Affix>
|
|
|
|
<span />
|
|
|
|
</Affix>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
jest.runAllTimers();
|
|
|
|
|
|
|
|
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>,
|
|
|
|
);
|
|
|
|
|
|
|
|
jest.runAllTimers();
|
|
|
|
|
|
|
|
expect(getTargetContainer).toHaveBeenCalled();
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
});
|