From 7a39033e6bcbaa9ceba5b741885957366aa4d6f3 Mon Sep 17 00:00:00 2001 From: kooff88 <597292454@qq.com> Date: Fri, 1 Dec 2017 20:30:08 +0800 Subject: [PATCH] Test(Switch):Add switch test (#37) --- src/switch/__test__/Switch.test.js | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/switch/__test__/Switch.test.js diff --git a/src/switch/__test__/Switch.test.js b/src/switch/__test__/Switch.test.js new file mode 100644 index 0000000000..a323798c8d --- /dev/null +++ b/src/switch/__test__/Switch.test.js @@ -0,0 +1,42 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import { Switch } from '../../../src'; + +describe('', () => { + const wrapperState = { + value: 0, + }; + const wrapper = mount( { + wrapperState.value = checked; + }} + />); + it('Test the default props and node.', () => { + expect(wrapper.name()).toBe('Switch'); + // 默认值测试 + expect(wrapper.find('.w-switch')).toHaveLength(1); + expect(wrapper.type()).toEqual(Switch); + expect(wrapper.at(0).prop('prefixCls')).toBe('w-switch'); + expect(wrapper.at(0).prop('size')).toBe('default'); + expect(wrapper.at(0).prop('disabled')).toBe(false); + expect(wrapper.at(0).prop('checked')).toBe(false); + }); + + it('Test checked attributes.', () => { + expect(wrapper.find('.w-switch').at(0).prop('className')).toBe('w-switch w-switch-default'); + wrapper.setProps({ checked: true }); + expect(wrapper.find('.w-switch').at(0).prop('className')).toBe('w-switch w-switch-checked w-switch-default'); + }); + + it('Test size attributes.', () => { + wrapper.setProps({ size: 'large' }); + expect(wrapper.find('.w-switch').at(0).prop('className')).toBe('w-switch w-switch-checked w-switch-large'); + }); + + it('Test onChange event.', () => { + const S = wrapper.find('.w-switch input').at(0); + S.simulate('change'); + expect(wrapperState.value).toBe(true); + expect(S.html()).toContain(''); + }); +});