Skip to content

Commit

Permalink
test(affix): split the last checkpoint (ant-design#37386)
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz authored Sep 5, 2022
1 parent 3b5c2f5 commit f212b33
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions components/affix/__tests__/Affix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,40 +191,42 @@ 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 = '<div id="mounter" />';

let affixInstance: InternalAffixClass | null = null;
const updateCalled = jest.fn();
const { container } = render(
render(
<AffixMounter
getInstance={inst => {
affixInstance = inst;
}}
offsetBottom={0}
onTestUpdatePosition={updateCalled}
/>,
{
container: document.getElementById('mounter')!,
},
);

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 <ResizeObserver>s.
it.each([
{ selector: '.ant-btn' }, // inner
{ selector: '.fixed' }, // outer
])('trigger listener when size change', async ({ selector }) => {
const updateCalled = jest.fn();
const { container } = render(
<AffixMounter offsetBottom={0} onTestUpdatePosition={updateCalled} />,
{
container: document.getElementById('mounter')!,
},
);

updateCalled.mockReset();
triggerResize(container.querySelector('.ant-btn')!);
triggerResize(container.querySelector(selector)!);
await sleep(20);
expect(updateCalled).toHaveBeenCalled();
});
Expand Down

0 comments on commit f212b33

Please sign in to comment.