2021-12-26 13:16:12 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-02-07 10:08:07 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2021-12-26 13:16:12 +08:00
|
|
|
import Counter from '../src/components/Counter.vue'
|
|
|
|
|
|
|
|
describe('Counter.vue', () => {
|
|
|
|
it('should render', () => {
|
|
|
|
const wrapper = mount(Counter, { props: { initial: 10 } })
|
|
|
|
expect(wrapper.text()).toContain('10')
|
|
|
|
expect(wrapper.html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
2022-05-01 11:52:59 +08:00
|
|
|
it('should be interactive', async () => {
|
2021-12-26 13:16:12 +08:00
|
|
|
const wrapper = mount(Counter, { props: { initial: 0 } })
|
|
|
|
expect(wrapper.text()).toContain('0')
|
|
|
|
|
|
|
|
expect(wrapper.find('.inc').exists()).toBe(true)
|
|
|
|
|
2022-04-08 18:32:53 +08:00
|
|
|
expect(wrapper.find('.dec').exists()).toBe(true)
|
|
|
|
|
|
|
|
await wrapper.get('.inc').trigger('click')
|
2021-12-26 13:16:12 +08:00
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('1')
|
2022-04-08 18:32:53 +08:00
|
|
|
|
|
|
|
await wrapper.get('.dec').trigger('click')
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('0')
|
2021-12-26 13:16:12 +08:00
|
|
|
})
|
|
|
|
})
|