ant-design/components/config-provider/__tests__/target.test.tsx
叶枫 502dac12aa
docs: format code (#48309)
* docs: fix code

* feat: lint

* feat: prettier

* feat: test

* feat: review

* feat: format html

* feat: format html
2024-04-08 14:04:08 +08:00

47 lines
1.0 KiB
TypeScript

import React from 'react';
import ConfigProvider from '..';
import { act, render } from '../../../tests/utils';
import Affix from '../../affix';
import Anchor from '../../anchor';
describe('ConfigProvider.getTargetContainer', () => {
it('Affix', () => {
jest.useFakeTimers();
const getTargetContainer = jest.fn(() => window);
render(
<ConfigProvider getTargetContainer={getTargetContainer}>
<Affix>
<span />
</Affix>
</ConfigProvider>,
);
act(() => {
jest.runAllTimers();
});
expect(getTargetContainer).toHaveBeenCalled();
jest.useRealTimers();
});
it('Anchor', () => {
jest.useFakeTimers();
const getTargetContainer = jest.fn(() => window);
render(
<ConfigProvider getTargetContainer={getTargetContainer}>
<Anchor>
<Anchor.Link href="#API" title="API" />
</Anchor>
</ConfigProvider>,
);
act(() => {
jest.runAllTimers();
});
expect(getTargetContainer).toHaveBeenCalled();
jest.useRealTimers();
});
});