HelloWorld.spec.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import HelloWorld from '@/views/HelloWorld.vue'
  2. import { mountComponent } from '@test/unit/testhelper'
  3. import { VueWrapper } from '@vue/test-utils'
  4. import { NButton } from 'naive-ui'
  5. import { ComponentPublicInstance } from 'vue'
  6. describe('HelloWorld.vue', () => {
  7. let wrapper: VueWrapper<ComponentPublicInstance<typeof HelloWorld>>
  8. beforeEach(() => {
  9. wrapper = mountComponent<InstanceType<typeof HelloWorld>>(HelloWorld, {
  10. props: { msg: 'foo bar' }
  11. })
  12. })
  13. afterEach(() => {
  14. wrapper?.unmount()
  15. })
  16. test('should mount', () => {
  17. expect(wrapper.findComponent(HelloWorld).exists()).toBe(true)
  18. })
  19. test('should disable button after 60 clicks', async () => {
  20. const nButton: VueWrapper<InstanceType<typeof NButton>> =
  21. wrapper.findComponent(NButton)
  22. expect(nButton.exists()).toBe(true)
  23. expect(nButton.attributes()).not.toHaveProperty('disabled')
  24. for (let i = 0; i < 61; i++) {
  25. ;(nButton.element as HTMLButtonElement).click()
  26. await wrapper.vm.$nextTick()
  27. }
  28. expect(nButton.attributes()).toHaveProperty('disabled')
  29. })
  30. })