提交 702396d0 编写于 作者: D dolymood

test(Rate): more tests

上级 a26b1ed1
......@@ -16,7 +16,7 @@ describe('Rate.vue', () => {
expect(Vue.component(Rate.name))
.to.be.a('function')
})
it('should render correct contents', () => {
it('should render correct contents', (done) => {
vm = createRate()
const el = vm.$el
expect(el.className)
......@@ -27,11 +27,22 @@ describe('Rate.vue', () => {
const stars = el.querySelectorAll('.cube-rate-item')
expect(stars.length)
.to.equal(vm.max)
vm.$parent.value = 4
vm.$parent.justify = true
setTimeout(() => {
expect(el.className)
.to.equal('cube-rate cube-rate-justify')
const actives = el.querySelectorAll('.cube-rate-item_active')
expect(actives.length)
.to.equal(vm.value)
done()
})
})
it('should trigger change event', function (done) {
this.timeout(10000)
const changeHandler = sinon.spy()
vm = createRate(changeHandler)
vm.$parent.disabled = true
setTimeout(() => {
// dispatch touch
dispatchSwipe(vm.$el, [
......@@ -44,11 +55,29 @@ describe('Rate.vue', () => {
pageY: 20
}
], 100)
// No response
setTimeout(() => {
expect(changeHandler).to.be.calledOnce
done()
}, 600)
}, 2000)
expect(changeHandler).not.to.be.called
vm.$parent.disabled = false
setTimeout(() => {
// dispatch touch again
dispatchSwipe(vm.$el, [
{
pageX: 50,
pageY: 20
},
{
pageX: 180,
pageY: 20
}
], 100)
setTimeout(() => {
expect(changeHandler).to.be.calledOnce
done()
}, 200)
})
}, 200)
})
})
it('should trigger change event with click', function (done) {
this.timeout(10000)
......@@ -69,12 +98,13 @@ describe('Rate.vue', () => {
function createRate (changeHanlder) {
const vm = createVue({
template: `
<cube-rate v-model="value" :disabled="disabled" :max="max"></cube-rate>
<cube-rate v-model="value" :disabled="disabled" :justify="justify" :max="max"></cube-rate>
`,
data: {
disabled: false,
value: 3,
max: 5
max: 5,
justify: false
},
watch: {
value(newVal) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册