Skip to content

Commit 50e4846

Browse files
author
刘欢
committed
test: add itemRender test
1 parent b876296 commit 50e4846

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/index.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,5 +817,29 @@ describe('Segmented keyboard navigation', () => {
817817
const labels = container.querySelectorAll('.test-title');
818818
expect(labels).toHaveLength(3);
819819
});
820+
it('should pass complete params to itemRender', () => {
821+
const mockItemRender = jest.fn((node, params) => node);
822+
const testData = {
823+
label: 'iOS',
824+
value: 'iOS',
825+
disabled: false,
826+
title: 'iOS',
827+
};
828+
render(
829+
<Segmented
830+
options={[{ ...testData, className: 'test-class' }, 'Android', 'Web']}
831+
itemRender={mockItemRender}
832+
/>,
833+
);
834+
expect(mockItemRender).toHaveBeenCalledTimes(3);
835+
const callArgs = mockItemRender.mock.calls[0];
836+
const receivedParams = callArgs[1];
837+
expect(receivedParams).toEqual({
838+
item: {
839+
...testData,
840+
},
841+
});
842+
expect(React.isValidElement(callArgs[0])).toBeTruthy();
843+
});
820844
});
821845
});

0 commit comments

Comments
 (0)