Skip to content

Commit 1b4b79f

Browse files
authored
Merge pull request #382 from messenjer/feat/vitest
refactor: migrate to vitest
2 parents 265f323 + b295dc3 commit 1b4b79f

24 files changed

+72
-73
lines changed

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
'browser': true,
55
'es6': true,
66
'node': true,
7-
'jest/globals': true,
87
'vue/setup-compiler-macros': true,
98
},
109
extends: [
@@ -16,7 +15,6 @@ module.exports = {
1615
parserOptions: {
1716
ecmaVersion: 2021,
1817
},
19-
plugins: ['jest'],
2018
rules: {
2119
'no-alert': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
2220
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',

jest.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"docs:deploy": "./scripts/deploy.sh",
3737
"test": "npm run test:lint && npm run test:unit",
3838
"test:lint": "npm run lint",
39-
"test:unit": "jest",
39+
"test:unit": "vitest",
4040
"prepare": "husky install && vite build",
4141
"publish": "npm publish --tag develop",
4242
"release": "standard-version"
@@ -51,7 +51,6 @@
5151
"@babel/core": "7.x.x",
5252
"@babel/plugin-transform-runtime": "7.x.x",
5353
"@babel/preset-env": "7.x.x",
54-
"@testing-library/jest-dom": "5.x.x",
5554
"@types/bootstrap": "5.x.x",
5655
"@typescript-eslint/eslint-plugin": "5.x.x",
5756
"@typescript-eslint/parser": "5.x.x",
@@ -61,23 +60,21 @@
6160
"@vue/test-utils": "^2.0.0-rc.14",
6261
"eslint": "8.x.x",
6362
"eslint-config-prettier": "8.x.x",
64-
"eslint-plugin-jest": "26.x.x",
6563
"eslint-plugin-vue": "8.x.x",
6664
"husky": "^7.0.2",
6765
"improved-yarn-audit": "3.x.x",
68-
"jest": "^27.0.6",
66+
"jsdom": "^19.0.0",
6967
"lint-staged": "12.x.x",
7068
"prettier": "^2.3.2",
7169
"rollup-plugin-visualizer": "5.x.x",
7270
"sass": "1.x.x",
7371
"standard-version": "^9.3.2",
74-
"ts-jest": "^27.0.4",
7572
"typescript": "4.x.x",
7673
"vite": "2.x.x",
7774
"vite-plugin-dts": "1.x.x",
75+
"vitest": "^0.10.4",
7876
"vue": "3.x.x",
79-
"vue-router": "4.x.x",
80-
"vue3-jest": "^27.0.0-alpha.2"
77+
"vue-router": "4.x.x"
8178
},
8279
"repository": {
8380
"type": "git",

src/components/BFormCheckbox/BFormCheckbox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default defineComponent({
110110
const inputClasses = getInputClasses(props)
111111
const labelClasses = getLabelClasses(props)
112112
113-
// TODO: make jest tests compatible with the v-focus directive
113+
// TODO: make tests compatible with the v-focus directive
114114
if (props.autofocus) {
115115
onMounted(() => {
116116
input.value.focus()

src/components/BFormCheckbox/BFormCheckboxGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default defineComponent({
8888
const attrs = getGroupAttr(props)
8989
const classes = getGroupClasses(props)
9090
91-
// TODO: make jest tests compatible with the v-focus directive
91+
// TODO: make tests compatible with the v-focus directive
9292
9393
return {
9494
attrs,

src/components/BFormCheckbox/form-checkbox-group.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import {describe, expect, it} from 'vitest'
12
import {mount} from '@vue/test-utils'
23
import {createContainer, waitNT} from '../../../tests/utils'
3-
import BFormCheckboxGroup from './BFormCheckboxGroup'
4-
import BFormCheckbox from './BFormCheckbox'
4+
import BFormCheckboxGroup from './BFormCheckboxGroup.vue'
5+
import BFormCheckbox from './BFormCheckbox.vue'
56

67
const global = {components: {BFormCheckbox}}
78

src/components/BFormCheckbox/form-checkbox.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {mount} from '@vue/test-utils'
2+
import {afterEach, beforeEach, describe, expect, it, vitest} from 'vitest'
3+
24
import {createContainer, waitNT, waitRAF} from '../../../tests/utils'
3-
import BFormCheckbox from './BFormCheckbox'
5+
import BFormCheckbox from './BFormCheckbox.vue'
46

57
describe('form-checkbox', () => {
68
// --- Custom checkbox structure, class and attributes tests ---
@@ -1514,7 +1516,7 @@ describe('form-checkbox', () => {
15141516
beforeEach(() => {
15151517
// Mock `getBoundingClientRect()` so that the `isVisible(el)` test returns `true`
15161518
// In our test below, all pagination buttons would normally be visible
1517-
Element.prototype.getBoundingClientRect = jest.fn(() => ({
1519+
Element.prototype.getBoundingClientRect = vitest.fn(() => ({
15181520
width: 24,
15191521
height: 24,
15201522
top: 0,

src/components/BFormInput/form-input.spec.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {mount} from '@vue/test-utils'
2+
import {afterEach, beforeEach, describe, expect, it, vitest} from 'vitest'
3+
24
import {createContainer, waitNT, waitRAF} from '../../../tests/utils'
3-
import BFormInput from './BFormInput'
5+
import BFormInput from './BFormInput.vue'
46

57
describe('form-input', () => {
68
it('has class form-control', async () => {
@@ -220,7 +222,7 @@ describe('form-input', () => {
220222
})
221223

222224
it('renders text input when type not supported', async () => {
223-
const warnHandler = jest.fn()
225+
const warnHandler = vitest.fn()
224226

225227
const wrapper = mount(BFormInput, {
226228
global: {
@@ -394,7 +396,7 @@ describe('form-input', () => {
394396
})
395397

396398
it('emits a native focus event', async () => {
397-
const spy = jest.fn()
399+
const spy = vitest.fn()
398400
const wrapper = mount(BFormInput, {
399401
attrs: {
400402
onFocus: spy,
@@ -622,7 +624,7 @@ describe('form-input', () => {
622624

623625
/* TODO: implement noWheel
624626
it('focused number input with no-wheel set to true works', async () => {
625-
const spy = jest.fn()
627+
const spy = vitest.fn()
626628
const wrapper = mount(BFormInput, {
627629
attachTo: createContainer(),
628630
props: {
@@ -650,7 +652,7 @@ describe('form-input', () => {
650652
651653
652654
it('focused number input with no-wheel set to false works', async () => {
653-
const spy = jest.fn(() => {})
655+
const spy = vitest.fn(() => {})
654656
const wrapper = mount(BFormInput, {
655657
attachTo: createContainer(),
656658
props: {
@@ -680,7 +682,7 @@ describe('form-input', () => {
680682
681683
682684
it('changing no-wheel after mount works', async () => {
683-
const spy = jest.fn(() => {})
685+
const spy = vitest.fn(() => {})
684686
const wrapper = mount(BFormInput, {
685687
attachTo: createContainer(),
686688
props: {
@@ -823,7 +825,7 @@ describe('form-input', () => {
823825

824826
/* TODO: implement debounce
825827
it('"debounce" prop works', async () => {
826-
jest.useFakeTimers()
828+
vitest.useFakeTimers()
827829
const wrapper = mount(BFormInput, {
828830
props: {
829831
type: 'text',
@@ -853,7 +855,7 @@ describe('form-input', () => {
853855
expect(wrapper.emitted('input')[1][0]).toBe('ab')
854856
855857
// Advance timer
856-
jest.runOnlyPendingTimers()
858+
vitest.runOnlyPendingTimers()
857859
// Should update the v-model
858860
expect($input.element.value).toBe('ab')
859861
// `v-model` update event should have emitted
@@ -911,7 +913,7 @@ describe('form-input', () => {
911913
expect(wrapper.emitted('input')[5][0]).toBe('abcd')
912914
913915
// Advance timer
914-
jest.runOnlyPendingTimers()
916+
vitest.runOnlyPendingTimers()
915917
// Should update the v-model
916918
expect($input.element.value).toBe('abcd')
917919
// `v-model` update event should not have emitted new event
@@ -929,7 +931,7 @@ describe('form-input', () => {
929931

930932
beforeEach(() => {
931933
// Mock `getBoundingClientRect()` so that the `isVisible(el)` test returns `true`
932-
Element.prototype.getBoundingClientRect = jest.fn(() => ({
934+
Element.prototype.getBoundingClientRect = vitest.fn(() => ({
933935
width: 24,
934936
height: 24,
935937
top: 0,

src/components/BFormRadio/BFormRadio.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default defineComponent({
8282
const inputClasses = getInputClasses(props)
8383
const labelClasses = getLabelClasses(props)
8484
85-
// TODO: make jest tests compatible with the v-focus directive
85+
// TODO: make tests compatible with the v-focus directive
8686
if (props.autofocus) {
8787
onMounted(() => {
8888
input.value.focus()

src/components/BFormRadio/BFormRadioGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default defineComponent({
8282
const attrs = getGroupAttr(props)
8383
const classes = getGroupClasses(props)
8484
85-
// TODO: make jest tests compatible with the v-focus directive
85+
// TODO: make tests compatible with the v-focus directive
8686
8787
return {
8888
attrs,

0 commit comments

Comments
 (0)