2019-03-15 11:42:41 +08:00
|
|
|
import { flushPromises } from '../../utils'
|
2019-11-30 12:01:17 +08:00
|
|
|
import { showModal } from '@/scripts/notify'
|
2020-01-06 22:47:29 +08:00
|
|
|
import { post } from '@/scripts/net'
|
|
|
|
import handler from '@/views/admin/Update'
|
2018-09-13 18:10:23 +08:00
|
|
|
|
2019-11-30 12:01:17 +08:00
|
|
|
jest.mock('@/scripts/notify')
|
2020-01-06 22:47:29 +08:00
|
|
|
jest.mock('@/scripts/net')
|
2019-11-30 12:01:17 +08:00
|
|
|
|
2020-01-06 22:47:29 +08:00
|
|
|
test('click button', async () => {
|
2020-05-16 22:05:16 +08:00
|
|
|
post
|
|
|
|
.mockResolvedValueOnce({ code: 1, message: 'failed' })
|
2020-01-06 22:47:29 +08:00
|
|
|
.mockResolvedValue({ code: 0, message: 'ok' })
|
2019-03-17 10:21:18 +08:00
|
|
|
|
2020-01-06 22:47:29 +08:00
|
|
|
const button = document.createElement('button')
|
|
|
|
button.addEventListener('click', handler)
|
2018-09-13 18:10:23 +08:00
|
|
|
|
2020-01-06 22:47:29 +08:00
|
|
|
const event = new MouseEvent('click')
|
|
|
|
button.dispatchEvent(event)
|
2019-03-15 11:42:41 +08:00
|
|
|
await flushPromises()
|
2020-01-06 22:47:29 +08:00
|
|
|
expect(showModal).toBeCalledWith({ mode: 'alert', text: 'failed' })
|
2019-04-05 17:23:27 +08:00
|
|
|
|
2020-01-06 22:47:29 +08:00
|
|
|
button.dispatchEvent(event)
|
2019-03-15 11:42:41 +08:00
|
|
|
await flushPromises()
|
2020-01-06 22:47:29 +08:00
|
|
|
expect(showModal).toBeCalledWith({ mode: 'alert', text: 'ok' })
|
2019-03-15 11:42:41 +08:00
|
|
|
})
|