From c510029923e55833f07aba8584d2fcc29ac57f7c Mon Sep 17 00:00:00 2001 From: rubenmoya Date: Tue, 20 Feb 2018 21:00:47 +0100 Subject: [PATCH] Update tests to use Enzyme 3 --- components/chip/__test__/index.spec.js | 6 +++--- components/progress_bar/__test__/index.spec.js | 10 +++++----- components/slider/__tests__/index.spec.js | 12 ++++++------ components/tabs/__tests__/index.spec.js | 6 ++++++ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/components/chip/__test__/index.spec.js b/components/chip/__test__/index.spec.js index fa427433..78178f0f 100644 --- a/components/chip/__test__/index.spec.js +++ b/components/chip/__test__/index.spec.js @@ -17,7 +17,7 @@ describe('Chip', () => { Test , ); - const chipNode = wrapper.find('div').node; + const chipNode = wrapper.find('div').instance(); expect(chipNode.className).toMatch(/\bavatar-class\b/); }); @@ -29,7 +29,7 @@ describe('Chip', () => { Test , ); - const chipNode = wrapper.find('div').node; + const chipNode = wrapper.find('div').instance(); expect(chipNode.className).toMatch(/\bavatar-class\b/); }); }); @@ -41,7 +41,7 @@ describe('Chip', () => { Test , ); - const chipNode = wrapper.find('div').node; + const chipNode = wrapper.find('div').instance(); expect(chipNode.className).not.toMatch(/\bavatar-class\b/); }); }); diff --git a/components/progress_bar/__test__/index.spec.js b/components/progress_bar/__test__/index.spec.js index 36be9b7e..2a9c1a22 100644 --- a/components/progress_bar/__test__/index.spec.js +++ b/components/progress_bar/__test__/index.spec.js @@ -27,25 +27,25 @@ describe('ProgressBar', () => { describe('#render', () => { it('renders the value and buffer bars when it is linear', () => { const wrapper = mount(); - expect(wrapper.childAt(0).props().children.length).toEqual(2); + expect(wrapper.childAt(0).childAt(0).props().children.length).toEqual(2); }); it('renders the value and buffer bars when it is linear', () => { const wrapper = mount(); - const buffer = wrapper.childAt(0).childAt(0); - const value = wrapper.childAt(0).childAt(1); + const buffer = wrapper.childAt(0).childAt(0).childAt(0); + const value = wrapper.childAt(0).childAt(0).childAt(1); expect(buffer.props().style.transform).toEqual(`scaleX(${0.6})`); expect(value.props().style.transform).toEqual(`scaleX(${0.3})`); }); it('renders the svg circle when it is circular', () => { const wrapper = mount(); - expect(wrapper.childAt(0).props().children.type).toEqual('circle'); + expect(wrapper.childAt(0).childAt(0).props().children.type).toEqual('circle'); }); it('renders the proper circle length style when it is circular and determinate', () => { const wrapper = mount(); - const circle = wrapper.childAt(0).props().children; + const circle = wrapper.childAt(0).childAt(0).props().children; const strokeLength = 2 * Math.PI * circle.props.r * 0.3; expect(circle.props.style.strokeDasharray).toEqual(`${strokeLength}, 400`); }); diff --git a/components/slider/__tests__/index.spec.js b/components/slider/__tests__/index.spec.js index 6a5c429e..bd312cb7 100644 --- a/components/slider/__tests__/index.spec.js +++ b/components/slider/__tests__/index.spec.js @@ -93,7 +93,7 @@ describe('Slider', () => { it('sets pressed state when knob is clicked', () => { const onChange = jest.fn(); const wrapper = mount(); - const knob = wrapper.childAt(0).childAt(0); + const knob = wrapper.childAt(0).childAt(0).childAt(0); knob.simulate('mouseDown'); expect(wrapper.state().pressed).toEqual(true); }); @@ -102,7 +102,7 @@ describe('Slider', () => { const onChange = jest.fn(); const event = { touches: [{ pageX: 200 }] }; const wrapper = mount(); - const knob = wrapper.childAt(0).childAt(0); + const knob = wrapper.childAt(0).childAt(0).childAt(0); knob.simulate('touchStart', event); expect(wrapper.state().pressed).toEqual(true); }); @@ -114,7 +114,7 @@ describe('Slider', () => { const instance = wrapper.instance(); instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.handleResize = (evt, callback) => { callback(); }; - wrapper.childAt(0).simulate('mouseDown', event); + wrapper.childAt(0).childAt(0).simulate('mouseDown', event); expect(onChange).toHaveBeenCalledWith(-300); }); @@ -125,7 +125,7 @@ describe('Slider', () => { const instance = wrapper.instance(); instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.handleResize = (evt, callback) => { callback(); }; - wrapper.childAt(0).simulate('touchStart', event); + wrapper.childAt(0).childAt(0).simulate('touchStart', event); expect(onChange).toHaveBeenCalledWith(-300); }); @@ -136,7 +136,7 @@ describe('Slider', () => { const instance = wrapper.instance(); instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.handleResize = (evt, callback) => { callback(); }; - wrapper.childAt(0).simulate('mouseDown', event); + wrapper.childAt(0).childAt(0).simulate('mouseDown', event); expect(onChange).toHaveBeenCalledWith(90); }); @@ -154,7 +154,7 @@ describe('Slider', () => { const onChange = jest.fn(); const wrapper = mount(); wrapper.instance().setState({ sliderStart: 0, sliderLength: 1000 }); - wrapper.childAt(0).simulate('mouseDown', { pageX: 900, pageY: 0 }); + wrapper.childAt(0).childAt(0).simulate('mouseDown', { pageX: 900, pageY: 0 }); expect(onChange).toHaveBeenCalled(); }); }); diff --git a/components/tabs/__tests__/index.spec.js b/components/tabs/__tests__/index.spec.js index 1bdd2e9f..249d4587 100644 --- a/components/tabs/__tests__/index.spec.js +++ b/components/tabs/__tests__/index.spec.js @@ -24,21 +24,27 @@ describe('Tabs', () => { it('defaults to only rendering the current tab', () => { const wrapper = mount(); + expect(wrapper.find(TabContent).length).toEqual(1); expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(0); wrapper.instance().setState({ index: 1 }); + wrapper.update(); + expect(wrapper.find(TabContent).length).toEqual(1); expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(1); }); it('renders inactive tabs when hideMode is set to display', () => { const wrapper = mount(); + expect(wrapper.find(TabContent).length).toEqual(2); expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(false); expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(true); wrapper.instance().setState({ index: 1 }); + wrapper.update(); + expect(wrapper.find(TabContent).length).toEqual(2); expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(true); expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(false);