vitesse/test/component.test.ts

29 lines
819 B
TypeScript
Raw Normal View History

2021-12-26 13:16:12 +08:00
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
2022-11-30 08:05:45 +08:00
import TheCounter from '../src/components/TheCounter.vue'
2021-12-26 13:16:12 +08:00
2022-11-30 08:05:45 +08:00
describe('TheCounter.vue', () => {
2021-12-26 13:16:12 +08:00
it('should render', () => {
2022-11-30 08:05:45 +08:00
const wrapper = mount(TheCounter, { props: { initial: 10 } })
2021-12-26 13:16:12 +08:00
expect(wrapper.text()).toContain('10')
expect(wrapper.html()).toMatchSnapshot()
})
2022-05-01 11:52:59 +08:00
it('should be interactive', async () => {
2022-11-30 08:05:45 +08:00
const wrapper = mount(TheCounter, { props: { initial: 0 } })
2021-12-26 13:16:12 +08:00
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
})
})