blessing-skin-server/resources/assets/tests/views/user/Bind.test.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-03-22 21:40:12 +08:00
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import Bind from '@/views/user/Bind.vue'
test('list existed players', async () => {
Vue.prototype.$http.get
2019-04-23 19:14:41 +08:00
.mockResolvedValue({ data: [{ name: 'a' }, { name: 'b' }] })
2019-03-22 21:40:12 +08:00
const wrapper = mount(Bind)
await wrapper.vm.$nextTick()
const options = wrapper.findAll('option')
expect(options).toHaveLength(2)
})
test('show input box', async () => {
2019-04-23 19:14:41 +08:00
Vue.prototype.$http.get.mockResolvedValue({ data: [] })
2019-03-22 21:40:12 +08:00
const wrapper = mount(Bind)
await wrapper.vm.$nextTick()
const input = wrapper.find('input')
expect(input.exists()).toBeTrue()
})
test('submit', async () => {
2019-04-23 19:14:41 +08:00
Vue.prototype.$http.get.mockResolvedValue({ data: [] })
2019-03-22 21:40:12 +08:00
Vue.prototype.$http.post
2019-04-23 11:47:45 +08:00
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
2019-03-22 21:40:12 +08:00
const wrapper = mount(Bind)
2019-03-27 11:50:39 +08:00
const form = wrapper.find('form')
2019-03-22 21:40:12 +08:00
wrapper.find('input').setValue('abc')
2019-03-27 11:50:39 +08:00
form.trigger('submit')
2019-03-22 21:40:12 +08:00
await wrapper.vm.$nextTick()
expect(wrapper.find('.callout').text()).toBe('fail')
2019-03-27 11:50:39 +08:00
form.trigger('submit')
2019-03-22 21:40:12 +08:00
await wrapper.vm.$nextTick()
2019-04-03 09:46:59 +08:00
expect(Vue.prototype.$alert).toBeCalledWith('ok')
2019-03-22 21:40:12 +08:00
})