test: add test coverage (#37993)

* test: add test coverage

* fix: fix

* test: del test

* fix: fix

* fix: fix

* chore: update test

* chore: code clean

* chore: code clean

* test: update test case

Co-authored-by: MadCcc <1075746765@qq.com>
This commit is contained in:
lijianan 2022-10-14 15:53:29 +08:00 committed by GitHub
parent 82de4942d5
commit 2ef701be75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import React from 'react';
import type { AffixProps, InternalAffixClass } from '..';
import type { InternalAffixClass } from '..';
import Affix from '..';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import rtlTest from '../../../tests/shared/rtlTest';
@ -120,9 +120,8 @@ describe('Affix Render', () => {
});
it('Anchor correct render when target is null', async () => {
expect(() => {
render(<Affix target={null as unknown as AffixProps['target']}>test</Affix>);
}).not.toThrow();
render(<Affix target={() => null}>test</Affix>);
await waitFakeTimer();
});
it('support offsetBottom', async () => {
@ -202,6 +201,21 @@ describe('Affix Render', () => {
expect(getObserverEntities()).toHaveLength(1);
expect(getObserverEntities()[0].target).toBe(window);
});
it('check position change before measure', async () => {
const { container } = render(
<>
<Affix offsetTop={10}>
<Button>top</Button>
</Affix>
<Affix offsetBottom={10}>
<Button>bottom</Button>
</Affix>
</>,
);
await waitFakeTimer();
await movePlaceholder(1000);
expect(container.querySelector('.ant-affix')).toBeTruthy();
});
});
describe('updatePosition when size changed', () => {