diff --git a/components/affix/__tests__/Affix.test.tsx b/components/affix/__tests__/Affix.test.tsx index 68f8c92306..bd37d46298 100644 --- a/components/affix/__tests__/Affix.test.tsx +++ b/components/affix/__tests__/Affix.test.tsx @@ -191,21 +191,16 @@ describe('Affix Render', () => { }); describe('updatePosition when size changed', () => { - it.each([ - { name: 'inner', index: 0 }, - { name: 'outer', index: 1 }, - ])('inner or outer', async () => { + it('add class automatically', async () => { document.body.innerHTML = '
'; let affixInstance: InternalAffixClass | null = null; - const updateCalled = jest.fn(); - const { container } = render( + render( { affixInstance = inst; }} offsetBottom={0} - onTestUpdatePosition={updateCalled} />, { container: document.getElementById('mounter')!, @@ -213,18 +208,25 @@ describe('Affix Render', () => { ); await sleep(20); - await movePlaceholder(300); expect(affixInstance!.state.affixStyle).toBeTruthy(); + }); - // Mock trigger resize - updateCalled.mockReset(); - triggerResize(container.querySelector('.fixed')!); - await sleep(20); - expect(updateCalled).toHaveBeenCalled(); + // Trigger inner and outer element for the two s. + it.each([ + { selector: '.ant-btn' }, // inner + { selector: '.fixed' }, // outer + ])('trigger listener when size change', async ({ selector }) => { + const updateCalled = jest.fn(); + const { container } = render( + , + { + container: document.getElementById('mounter')!, + }, + ); updateCalled.mockReset(); - triggerResize(container.querySelector('.ant-btn')!); + triggerResize(container.querySelector(selector)!); await sleep(20); expect(updateCalled).toHaveBeenCalled(); });