Skip to content

Commit aec2c26

Browse files
committed
chore: test refactoring
1 parent 730da96 commit aec2c26

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

test/createApp.spec.js renamed to test/createApp.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
const Vue = require('vue/dist/vue.common.js')
2-
const { createApp, defineComponent, ref, h } = require('../src')
1+
import { createApp, defineComponent, ref, nextTick } from '../src'
32

43
describe('createApp', () => {
54
it('should work', async () => {
6-
const vm = new Vue({
5+
const app = createApp({
76
setup() {
87
return {
98
a: ref(1),
109
}
1110
},
1211
template: '<p>{{a}}</p>',
13-
}).$mount()
12+
})
13+
const vm = app.mount()
1414

15-
await Vue.nextTick()
16-
expect(vm.a).toBe(1)
15+
await nextTick()
1716
expect(vm.$el.textContent).toBe('1')
1817
})
1918

@@ -31,7 +30,7 @@ describe('createApp', () => {
3130
)
3231
const vm = app.mount()
3332

34-
await Vue.nextTick()
33+
await nextTick()
3534
expect(vm.$el.textContent).toBe('foobar')
3635
})
3736

@@ -60,7 +59,7 @@ describe('createApp', () => {
6059
app.component('Foo', Foo)
6160
const vm = app.mount()
6261

63-
await Vue.nextTick()
62+
await nextTick()
6463
expect(vm.$el.textContent).toBe('foobar')
6564
})
6665
})

test/helpers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './mockWarn'
2+
export * from './utils'

test/misc.spec.js renamed to test/misc.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const Vue = require('vue/dist/vue.common.js')
2-
const { ref, nextTick } = require('../src')
1+
import Vue from './vue'
2+
import { ref, nextTick } from '../src'
33

44
describe('nextTick', () => {
5-
it('should works', () => {
6-
const vm = new Vue({
5+
it('should works with callbacks', () => {
6+
const vm = new Vue<{ a: number }>({
77
template: `<div>{{a}}</div>`,
88
setup() {
99
return {
@@ -28,7 +28,7 @@ describe('nextTick', () => {
2828
})
2929

3030
it('should works with await', async () => {
31-
const vm = new Vue({
31+
const vm = new Vue<{ a: number }>({
3232
template: `<div>{{a}}</div>`,
3333
setup() {
3434
return {

test/v3/reactivity/computed.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
ref,
55
watchEffect,
66
WritableComputedRef,
7+
nextTick,
78
} from '../../../src'
8-
import { mockWarn } from '../../helpers/mockWarn'
9-
import { nextTick } from '../../helpers/utils'
9+
import { mockWarn } from '../../helpers'
1010

1111
describe('reactivity/computed', () => {
1212
mockWarn(true)

test/v3/runtime-core/apiLifecycle.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
onUpdated,
1010
onBeforeUnmount,
1111
onUnmounted,
12+
nextTick,
1213
} from '../../../src'
13-
import { nextTick } from '../../helpers/utils'
1414

1515
// reference: https://vue-composition-api-rfc.netlify.com/api.html#lifecycle-hooks
1616

test/v3/runtime-core/apiWatch.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
ref,
77
set,
88
shallowReactive,
9+
nextTick,
910
} from '../../../src'
10-
import { nextTick } from '../../helpers/utils'
1111
import Vue from 'vue'
1212

1313
// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch
@@ -515,7 +515,6 @@ describe('api: watch', () => {
515515
// expect(warnSpy).toHaveBeenCalledWith(`"deep" option is only respected`);
516516
// });
517517

518-
519518
// #388
520519
it('should not call the callback multiple times', () => {
521520
const data = ref([1, 1, 1, 1, 1])

test/vue.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// `vue.common.js` is required for shallow mounts.
2+
// Typescript can not infer it properly, this file is a workround to set the type
3+
4+
// @ts-ignore
5+
import _vue from 'vue/dist/vue.common'
6+
import { VueConstructor } from 'vue'
7+
8+
export default (_vue as any) as VueConstructor

0 commit comments

Comments
 (0)