Update tests to use Enzyme 3

old
rubenmoya 2018-02-20 21:00:47 +01:00
parent d313e11a1f
commit c510029923
4 changed files with 20 additions and 14 deletions

View File

@ -17,7 +17,7 @@ describe('Chip', () => {
<span>Test</span> <span>Test</span>
</Chip>, </Chip>,
); );
const chipNode = wrapper.find('div').node; const chipNode = wrapper.find('div').instance();
expect(chipNode.className).toMatch(/\bavatar-class\b/); expect(chipNode.className).toMatch(/\bavatar-class\b/);
}); });
@ -29,7 +29,7 @@ describe('Chip', () => {
<span>Test</span> <span>Test</span>
</TooltippedChip>, </TooltippedChip>,
); );
const chipNode = wrapper.find('div').node; const chipNode = wrapper.find('div').instance();
expect(chipNode.className).toMatch(/\bavatar-class\b/); expect(chipNode.className).toMatch(/\bavatar-class\b/);
}); });
}); });
@ -41,7 +41,7 @@ describe('Chip', () => {
<span>Test</span> <span>Test</span>
</Chip>, </Chip>,
); );
const chipNode = wrapper.find('div').node; const chipNode = wrapper.find('div').instance();
expect(chipNode.className).not.toMatch(/\bavatar-class\b/); expect(chipNode.className).not.toMatch(/\bavatar-class\b/);
}); });
}); });

View File

@ -27,25 +27,25 @@ describe('ProgressBar', () => {
describe('#render', () => { describe('#render', () => {
it('renders the value and buffer bars when it is linear', () => { it('renders the value and buffer bars when it is linear', () => {
const wrapper = mount(<ProgressBar theme={theme} />); const wrapper = mount(<ProgressBar theme={theme} />);
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', () => { it('renders the value and buffer bars when it is linear', () => {
const wrapper = mount(<ProgressBar mode="determinate" value={30} buffer={60} theme={theme} />); const wrapper = mount(<ProgressBar mode="determinate" value={30} buffer={60} theme={theme} />);
const buffer = wrapper.childAt(0).childAt(0); const buffer = wrapper.childAt(0).childAt(0).childAt(0);
const value = wrapper.childAt(0).childAt(1); const value = wrapper.childAt(0).childAt(0).childAt(1);
expect(buffer.props().style.transform).toEqual(`scaleX(${0.6})`); expect(buffer.props().style.transform).toEqual(`scaleX(${0.6})`);
expect(value.props().style.transform).toEqual(`scaleX(${0.3})`); expect(value.props().style.transform).toEqual(`scaleX(${0.3})`);
}); });
it('renders the svg circle when it is circular', () => { it('renders the svg circle when it is circular', () => {
const wrapper = mount(<ProgressBar type="circular" theme={theme} />); const wrapper = mount(<ProgressBar type="circular" theme={theme} />);
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', () => { it('renders the proper circle length style when it is circular and determinate', () => {
const wrapper = mount(<ProgressBar type="circular" mode="determinate" value={30} theme={theme} />); const wrapper = mount(<ProgressBar type="circular" mode="determinate" value={30} theme={theme} />);
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; const strokeLength = 2 * Math.PI * circle.props.r * 0.3;
expect(circle.props.style.strokeDasharray).toEqual(`${strokeLength}, 400`); expect(circle.props.style.strokeDasharray).toEqual(`${strokeLength}, 400`);
}); });

View File

@ -93,7 +93,7 @@ describe('Slider', () => {
it('sets pressed state when knob is clicked', () => { it('sets pressed state when knob is clicked', () => {
const onChange = jest.fn(); const onChange = jest.fn();
const wrapper = mount(<Slider min={-500} max={500} onChange={onChange} />); const wrapper = mount(<Slider min={-500} max={500} onChange={onChange} />);
const knob = wrapper.childAt(0).childAt(0); const knob = wrapper.childAt(0).childAt(0).childAt(0);
knob.simulate('mouseDown'); knob.simulate('mouseDown');
expect(wrapper.state().pressed).toEqual(true); expect(wrapper.state().pressed).toEqual(true);
}); });
@ -102,7 +102,7 @@ describe('Slider', () => {
const onChange = jest.fn(); const onChange = jest.fn();
const event = { touches: [{ pageX: 200 }] }; const event = { touches: [{ pageX: 200 }] };
const wrapper = mount(<Slider min={-500} max={500} onChange={onChange} />); const wrapper = mount(<Slider min={-500} max={500} onChange={onChange} />);
const knob = wrapper.childAt(0).childAt(0); const knob = wrapper.childAt(0).childAt(0).childAt(0);
knob.simulate('touchStart', event); knob.simulate('touchStart', event);
expect(wrapper.state().pressed).toEqual(true); expect(wrapper.state().pressed).toEqual(true);
}); });
@ -114,7 +114,7 @@ describe('Slider', () => {
const instance = wrapper.instance(); const instance = wrapper.instance();
instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.setState({ sliderStart: 0, sliderLength: 1000 });
instance.handleResize = (evt, callback) => { callback(); }; instance.handleResize = (evt, callback) => { callback(); };
wrapper.childAt(0).simulate('mouseDown', event); wrapper.childAt(0).childAt(0).simulate('mouseDown', event);
expect(onChange).toHaveBeenCalledWith(-300); expect(onChange).toHaveBeenCalledWith(-300);
}); });
@ -125,7 +125,7 @@ describe('Slider', () => {
const instance = wrapper.instance(); const instance = wrapper.instance();
instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.setState({ sliderStart: 0, sliderLength: 1000 });
instance.handleResize = (evt, callback) => { callback(); }; instance.handleResize = (evt, callback) => { callback(); };
wrapper.childAt(0).simulate('touchStart', event); wrapper.childAt(0).childAt(0).simulate('touchStart', event);
expect(onChange).toHaveBeenCalledWith(-300); expect(onChange).toHaveBeenCalledWith(-300);
}); });
@ -136,7 +136,7 @@ describe('Slider', () => {
const instance = wrapper.instance(); const instance = wrapper.instance();
instance.setState({ sliderStart: 0, sliderLength: 1000 }); instance.setState({ sliderStart: 0, sliderLength: 1000 });
instance.handleResize = (evt, callback) => { callback(); }; instance.handleResize = (evt, callback) => { callback(); };
wrapper.childAt(0).simulate('mouseDown', event); wrapper.childAt(0).childAt(0).simulate('mouseDown', event);
expect(onChange).toHaveBeenCalledWith(90); expect(onChange).toHaveBeenCalledWith(90);
}); });
@ -154,7 +154,7 @@ describe('Slider', () => {
const onChange = jest.fn(); const onChange = jest.fn();
const wrapper = mount(<Slider editable value={50} onChange={onChange} />); const wrapper = mount(<Slider editable value={50} onChange={onChange} />);
wrapper.instance().setState({ sliderStart: 0, sliderLength: 1000 }); 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(); expect(onChange).toHaveBeenCalled();
}); });
}); });

View File

@ -24,21 +24,27 @@ describe('Tabs', () => {
it('defaults to only rendering the current tab', () => { it('defaults to only rendering the current tab', () => {
const wrapper = mount(<Composition />); const wrapper = mount(<Composition />);
expect(wrapper.find(TabContent).length).toEqual(1); expect(wrapper.find(TabContent).length).toEqual(1);
expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(0); expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(0);
wrapper.instance().setState({ index: 1 }); wrapper.instance().setState({ index: 1 });
wrapper.update();
expect(wrapper.find(TabContent).length).toEqual(1); expect(wrapper.find(TabContent).length).toEqual(1);
expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(1); expect(wrapper.find(TabContent).first().prop('tabIndex')).toEqual(1);
}); });
it('renders inactive tabs when hideMode is set to display', () => { it('renders inactive tabs when hideMode is set to display', () => {
const wrapper = mount(<Composition hideMode="display" />); const wrapper = mount(<Composition hideMode="display" />);
expect(wrapper.find(TabContent).length).toEqual(2); expect(wrapper.find(TabContent).length).toEqual(2);
expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(false); expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(false);
expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(true); expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(true);
wrapper.instance().setState({ index: 1 }); wrapper.instance().setState({ index: 1 });
wrapper.update();
expect(wrapper.find(TabContent).length).toEqual(2); expect(wrapper.find(TabContent).length).toEqual(2);
expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(true); expect(wrapper.find(TabContent).at(0).prop('hidden')).toEqual(true);
expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(false); expect(wrapper.find(TabContent).at(1).prop('hidden')).toEqual(false);