1 |
|
2 | import React, {Component, PropTypes} from 'react'
|
3 | import BaseButton from '../src/index';
|
4 | import { shallow, mount, render } from 'enzyme';
|
5 |
|
6 | describe('BaseButton', ()=> {
|
7 |
|
8 | const BaseData = {
|
9 | "bsStyle":"defalult"
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 | ,"bsSize":"defalult"
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 | ,"active":false
|
22 | |
23 |
|
24 |
|
25 |
|
26 | ,"disabled":false
|
27 | |
28 |
|
29 |
|
30 |
|
31 | ,"href":""
|
32 | ,"title":"测试11"
|
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 |