import React from 'react'; import Tabs from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { fireEvent, render } from '../../../tests/utils'; import { resetWarned } from '../../_util/warning'; const { TabPane } = Tabs; describe('Tabs', () => { mountTest(() => ( )); rtlTest(() => ( )); describe('editable-card', () => { let handleEdit: jest.Mock; let wrapper: ReturnType['container']; beforeEach(() => { handleEdit = jest.fn(); const { container } = render( foo {undefined} {null} {false} , ); wrapper = container; }); it('add card', () => { fireEvent.click(wrapper.querySelector('.ant-tabs-nav-add')!); expect(handleEdit.mock.calls[0][1]).toBe('add'); }); it('remove card', () => { fireEvent.click(wrapper.querySelector('.anticon-close')!); expect(handleEdit).toHaveBeenCalledWith('1', 'remove'); }); it('validateElement', () => { expect(wrapper.querySelectorAll('.ant-tabs-tab').length).toBe(1); }); }); describe('tabPosition', () => { it('remove card', () => { const { container } = render( foo , ); expect(container.firstChild).toMatchSnapshot(); }); }); describe('renderTabBar', () => { it('custom-tab-bar', () => { const { container } = render(
custom-tab-bar
}> foo
, ); expect(container.firstChild).toMatchSnapshot(); }); }); it('warning for onNextClick', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const onNextClick = { onNextClick() {} } as any; render(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tabs] `onPrevClick` and `onNextClick` has been removed. Please use `onTabScroll` instead.', ); errorSpy.mockRestore(); }); it('tabBarGutter should work', () => { const { container: wrapper } = render( , ); expect(wrapper.firstChild).toMatchSnapshot(); const { container: wrapper2 } = render( , ); expect(wrapper2.firstChild).toMatchSnapshot(); }); it('deprecated warning', () => { resetWarned(); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const { container } = render( invalidate , ); expect(container.querySelectorAll('.ant-tabs-tab')).toHaveLength(1); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tabs] Tabs.TabPane is deprecated. Please use `items` directly.', ); errorSpy.mockRestore(); }); });