Skip to content

Commit

Permalink
test(lib): rewrite spec for TimepickerMixin in TS
Browse files Browse the repository at this point in the history
Rewrites `src/utils/TimepickerMixin.spec.js` in TypeScript.

Passes "0" to the `onSecondsChange` method, because it now requires a
string.

Moves the definition of the test component before `wrapper` so that
`wrapper` can be properly typed with `VueWrapper`.

Trivial changes:
- Replaces the extension: ".js" → ".ts"
- Imports the spec building blocks from the `vitest` package
- Replaces `jest` with `vi`
  • Loading branch information
kikuomax committed Jan 11, 2025
1 parent f2c8f6a commit ad5ab48
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent } from 'vue'
import { shallowMount } from '@vue/test-utils'
import type { VueWrapper } from '@vue/test-utils'
import TimepickerMixin from '@utils/TimepickerMixin'

const AM = 'AM'
const PM = 'PM'
let wrapper

const component = defineComponent({
mixins: [TimepickerMixin],
template: '<div class="b-component"></div>'
})

let wrapper: VueWrapper<InstanceType<typeof component>>

describe('TimepickerMixin', () => {
HTMLElement.prototype.insertAdjacentElement = jest.fn()
HTMLElement.prototype.insertAdjacentElement = vi.fn()
beforeEach(() => {
const component = {
template: '<div class="b-component"></div>',
mixins: [TimepickerMixin]
}
wrapper = shallowMount(component, {
attachTo: document.body
})
Expand All @@ -30,8 +35,8 @@ describe('TimepickerMixin', () => {
})

it('should call updateDateSelected on onSecondsChange', async () => {
wrapper.vm.updateDateSelected = jest.fn()
wrapper.vm.onSecondsChange()
wrapper.vm.updateDateSelected = vi.fn()
wrapper.vm.onSecondsChange('0')
await wrapper.vm.$nextTick()
expect(wrapper.vm.updateDateSelected).toHaveBeenCalledTimes(1)
})
Expand All @@ -55,14 +60,14 @@ describe('TimepickerMixin', () => {
})

it('should call onFocus on handleOnFocus', async () => {
wrapper.vm.onFocus = jest.fn()
wrapper.vm.onFocus = vi.fn()
wrapper.vm.handleOnFocus()
await wrapper.vm.$nextTick()
expect(wrapper.vm.onFocus).toHaveBeenCalledTimes(1)
})

it('should call toggle on close', async () => {
wrapper.vm.toggle = jest.fn()
wrapper.vm.toggle = vi.fn()
wrapper.vm.close()
await wrapper.vm.$nextTick()
expect(wrapper.vm.toggle).toHaveBeenCalledTimes(1)
Expand Down

0 comments on commit ad5ab48

Please sign in to comment.