import { mount, render } from 'enzyme'; import Tab, { TabBar } from '../index'; describe('Tab', () => { describe('Snapshots', () => { it('Deselected', () => { const wrapper = render(Foo); expect(wrapper).toMatchSnapshot(); }); it('Selected', () => { const wrapper = render( Foo ); expect(wrapper).toMatchSnapshot(); }); it('Deselected (rounded variant)', () => { const wrapper = render( Foo ); expect(wrapper).toMatchSnapshot(); }); it('Selected (rounded variant)', () => { const wrapper = render( Foo ); expect(wrapper).toMatchSnapshot(); }); }); describe('Functions', () => { it('trigger onTabChange when clicked', () => { const tabChangeHandler = jest.fn(); const wrapper = mount( Foo ); wrapper.find('button').simulate('click'); expect(tabChangeHandler).toHaveBeenCalledTimes(1); }); }); }); describe('TabBar', () => { describe('Snapshots', () => { it('No tabs', () => { const wrapper = render(); expect(wrapper).toMatchSnapshot(); }); it('Some tabs', () => { const wrapper = render( Foo Bar ); expect(wrapper).toMatchSnapshot(); }); it('Selected tabs', () => { const wrapper = render( Foo Bar ); expect(wrapper).toMatchSnapshot(); }); it('Rounded variant', () => { const wrapper = render( Foo Bar ); expect(wrapper).toMatchSnapshot(); }); it('Non-tab children', () => { const wrapper = render(Not a tab at all.); expect(wrapper).toMatchSnapshot(); }); }); describe('Functions', () => { it('calls onTabChange when a tab is clicked', () => { const tabChangeHandler = jest.fn(); const wrapper = mount( Foo Bar ); wrapper .find('Tab[name="bar"]') .find('button') .simulate('click'); expect(tabChangeHandler).toHaveBeenCalledWith('bar'); }); }); });