Commit 0f8452047db35074af15bcaf0bfafa2c67561d78
1 parent
9c33c644
[unit] 定义更多button测试用例
Showing
1 changed file
with
42 additions
and
0 deletions
Show diff stats
test/unit/specs/button.spec.js
| ... | ... | @@ -21,4 +21,46 @@ describe('Button.vue', () => { |
| 21 | 21 | expect(vm.$el.tagName).to.equal('BUTTON'); |
| 22 | 22 | done(); |
| 23 | 23 | }); |
| 24 | + | |
| 25 | + it('handle with `type` attribute', done => { | |
| 26 | + // should render with `type` attribute | |
| 27 | + // if it is a <button> | |
| 28 | + vm = createVue(` | |
| 29 | + <Button htmlType="reset">Think in FE</Button> | |
| 30 | + `); | |
| 31 | + expect(vm.$el.getAttribute('type')).to.equal('reset'); | |
| 32 | + | |
| 33 | + // should't render with `type` attribute | |
| 34 | + // if it is a <button> | |
| 35 | + vm = createVue(` | |
| 36 | + <Button to="http://www.thinkinfe.tech/" htmlType="reset">Think in FE</Button> | |
| 37 | + `); | |
| 38 | + expect(vm.$el.getAttribute('type')).to.equal(null); | |
| 39 | + done(); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + it('should change loading state', done => { | |
| 43 | + vm = createVue({ | |
| 44 | + template: ` | |
| 45 | + <Button :loading="loading" @click="fetch">Think in FE</Button> | |
| 46 | + `, | |
| 47 | + data() { | |
| 48 | + return {loading: false}; | |
| 49 | + }, | |
| 50 | + methods: { | |
| 51 | + fetch() { | |
| 52 | + this.loading = true; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + }); | |
| 56 | + vm.$el.click(); | |
| 57 | + vm.$nextTick(() => { | |
| 58 | + expect(vm.$el.classList.contains('ivu-btn-loading')).to.equal(true); | |
| 59 | + const $icons = vm.$el.querySelectorAll('.ivu-icon'); | |
| 60 | + expect($icons.length).to.equal(1); | |
| 61 | + expect($icons[0].classList.contains('ivu-load-loop')).to.equal(true); | |
| 62 | + expect($icons[0].classList.contains('ivu-icon-ios-loading')).to.equal(true); | |
| 63 | + done(); | |
| 64 | + }); | |
| 65 | + }); | |
| 24 | 66 | }); | ... | ... |