UNPKG

3.17 kBJavaScriptView Raw
1
2import React, {Component, PropTypes} from 'react'
3import BaseButton from '../src/index';
4import { shallow, mount, render } from 'enzyme';
5
6describe('BaseButton', ()=> {
7
8 const BaseData = {
9 "bsStyle":"defalult"
10 /**按钮类型(string)。参数:
11 1.默认:""或者“defalult”
12 2.弱化按钮:“weaken”
13 3.连接按钮:“link”
14 **/
15 ,"bsSize":"defalult"
16 /**按钮尺寸(string)。参数:
17 1.默认:""或者“defalult”
18 2.小按钮:“small”
19 3.块状按钮:“block”
20 **/
21 ,"active":false
22 /**是否选中(Boolean)。参数:
23 1.默认未选中:false
24 2.选中:true
25 **/
26 ,"disabled":false
27 /**是否禁用(Boolean)。参数:
28 1.默认不禁用:false
29 2.禁用:true
30 **/
31 ,"href":"" /**如果该字段有定义且非空,return(<a/>),否则return(</button>)**/
32 ,"title":"测试11" /**显示文本(string)**/
33 ,"hidden":false
34 ,"onClick":function(){console.log('点击')} /**点击后时间回调**/
35 }
36
37 // 渲染成功
38 it('render correct', () => {
39 const baseButton = render(<BaseButton data={BaseData}/>);
40 expect(baseButton.text()).toEqual("测试11");
41 })
42
43 // 按钮激活验证
44 it('active correct', () => {
45 const baseButton = render(<BaseButton data={BaseData}/>);
46 expect(baseButton.hasClass('base-bg-ripple-active')).not.actual;
47 })
48
49 // 按钮尺寸验证
50 it('bsSize correct', () => {
51 const baseButton = render(<BaseButton data={BaseData}/>);
52 expect(baseButton.hasClass('base-btns-bgc-big')).tactual;
53 })
54
55 // 按钮类型验证
56 it('bsStyle correct', () => {
57 const baseButton = render(<BaseButton data={BaseData}/>);
58 expect(baseButton.hasClass('base-btns-weaken')).tactual;
59 })
60
61 // willMount验证
62 it('componentWillMount execute correct', () => {
63 spyOn(BaseButton.prototype, "componentWillMount");
64 mount(<BaseButton data={BaseData}/>);
65 expect(BaseButton.prototype.componentWillMount).toHaveBeenCalled();
66 })
67
68 // click事件验证
69 it('simulates click events', () => {
70 const onButtonClick = jasmine.createSpy('111');
71 const baseButton = mount(<BaseButton bnRipple={onButtonClick} data={BaseData}/>);
72 baseButton.simulate('click');
73 const active = baseButton.state('btnActive');
74 expect(active).tactual;
75 });
76
77})
\No newline at end of file