test: add button test

This commit is contained in:
tjz 2018-05-13 12:01:52 +08:00
parent d0c5a708cf
commit d86e333491
3 changed files with 102 additions and 0 deletions

View File

@ -6,3 +6,23 @@
"<button type=\"button\" class=\"ant-btn ant-btn-primary\"><span>按 钮</span></button>"
```
#### `should support link button`
```
"<button target=\"_blank\" href=\"http://ant.design\" type=\"button\" class=\"ant-btn ant-btn-default\"><span>link button</span></button>"
```
#### `fixbug renders {0} , 0 and {false}`
```
"<button type=\"button\" class=\"ant-btn ant-btn-default\"><span>0</span></button>"
```
```
"<button type=\"button\" class=\"ant-btn ant-btn-default\"><span>0</span></button>"
```
```
"<button type=\"button\" class=\"ant-btn ant-btn-default\"></button>"
```

View File

@ -56,5 +56,85 @@ describe('Button', () => {
done()
})
})
it('should change loading state instantly by default', () => {
const DefaultButton = {
data(){
return {
loading: false,
}
},
methods: {
enterLoading () {
this.loading = true
}
},
render() {
return <Button loading={this.loading} onClick={this.enterLoading}>Button</Button>;
}
}
const wrapper = mount(DefaultButton)
wrapper.trigger('click');
Vue.nextTick(() => {
expect(wrapper.find('.ant-btn-loading').length).to.equal(1);
})
});
it('should change loading state with delay', () => {
const DefaultButton = {
data(){
return {
loading: false,
}
},
methods: {
enterLoading () {
this.loading = { delay: 1000 }
}
},
render() {
return <Button loading={this.loading} onClick={this.enterLoading}>Button</Button>;
}
}
const wrapper = mount(DefaultButton)
wrapper.trigger('click');
Vue.nextTick(() => {
expect(wrapper.hasClass('ant-btn-loading').length).to.equal(false);
})
});
it('should support link button', () => {
const wrapper = mount({
render (h) {
return <Button target="_blank" href="http://ant.design">link button</Button>
},
})
expect(wrapper.html()).to.matchSnapshot();
})
it('fixbug renders {0} , 0 and {false}', () => {
const wrapper = mount({
render (h) {
return <Button>{0}</Button>
},
})
expect(wrapper.html()).to.matchSnapshot();
const wrapper1 = mount({
render (h) {
return <Button>0</Button>
},
})
expect(wrapper1.html()).to.matchSnapshot();
const wrapper2 = mount({
render (h) {
return <Button>{false}</Button>
},
})
expect(wrapper2.html()).to.matchSnapshot();
})
})

View File

@ -146,10 +146,12 @@
"stylelint-config-standard": "^17.0.0",
"through2": "^2.0.3",
"validate-commit-msg": "^2.14.0",
"vue": "^2.5.16",
"vue-antd-md-loader": "^1.0.3",
"vue-clipboard2": "0.0.8",
"vue-loader": "^13.0.5",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.5.16",
"webpack": "^3.11.0",
"webpack-chunk-hash": "^0.5.0",
"webpack-dev-server": "^2.8.2",