element-plus/packages/rate/__tests__/rate.spec.ts

83 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-08-04 15:27:37 +08:00
import { mount } from '@vue/test-utils'
import Rate from '../src/index.vue'
describe('Rate.vue', () => {
2020-08-04 16:48:41 +08:00
test('create', () => {
2020-08-04 15:27:37 +08:00
const wrapper = mount(Rate, {
2020-08-04 16:48:41 +08:00
props: {
max: 10,
2020-08-04 15:27:37 +08:00
},
global: {
provide: {
elForm: {},
},
},
2020-08-04 15:27:37 +08:00
})
2020-08-05 13:14:20 +08:00
const stars = wrapper.findAll('.el-rate__item')
2020-08-04 16:48:41 +08:00
expect(stars.length).toEqual(10)
})
test('with texts', () => {
2020-08-05 13:14:20 +08:00
const wrapper = mount(Rate, {
2020-08-04 16:48:41 +08:00
props: {
showText: true,
modelValue: 4,
texts: ['1', '2', '3', '4', '5'],
},
global: {
provide: {
elForm: {},
},
},
2020-08-05 13:14:20 +08:00
})
const text = wrapper.find('.el-rate__text').element
2020-08-04 16:48:41 +08:00
expect(text.textContent).toEqual('4')
})
2020-08-05 13:14:20 +08:00
test('value change', async () => {
2020-08-04 16:48:41 +08:00
const wrapper = mount(Rate, {
props: {
modelValue: 0,
},
global: {
provide: {
elForm: {},
},
},
2020-08-04 16:48:41 +08:00
})
const vm = wrapper.vm
await wrapper.setProps({ modelValue: 3 })
expect(vm.modelValue).toEqual(3)
})
test('click', () => {
2020-08-05 13:14:20 +08:00
const wrapper = mount({
2020-08-04 16:48:41 +08:00
template: `
<div>
<el-rate v-model="value1" />
</div>
`,
props:{},
data() {
return {
value1: 0,
}
},
components: {
'el-rate': Rate,
},
}, {
global: {
provide: {
elForm: {},
},
2020-08-04 16:48:41 +08:00
},
2020-08-05 13:14:20 +08:00
})
const vm = wrapper.vm
const thirdStar = wrapper.findAll('.el-rate__item')[2].element as HTMLElement
2020-08-04 16:48:41 +08:00
thirdStar.click()
expect(vm.value1).toEqual(3)
2020-08-04 15:27:37 +08:00
})
})