Skip to content

Commit

Permalink
chore: test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 22, 2020
1 parent 730da96 commit aec2c26
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
15 changes: 7 additions & 8 deletions test/createApp.spec.js → test/createApp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const Vue = require('vue/dist/vue.common.js')
const { createApp, defineComponent, ref, h } = require('../src')
import { createApp, defineComponent, ref, nextTick } from '../src'

describe('createApp', () => {
it('should work', async () => {
const vm = new Vue({
const app = createApp({
setup() {
return {
a: ref(1),
}
},
template: '<p>{{a}}</p>',
}).$mount()
})
const vm = app.mount()

await Vue.nextTick()
expect(vm.a).toBe(1)
await nextTick()
expect(vm.$el.textContent).toBe('1')
})

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

await Vue.nextTick()
await nextTick()
expect(vm.$el.textContent).toBe('foobar')
})

Expand Down Expand Up @@ -60,7 +59,7 @@ describe('createApp', () => {
app.component('Foo', Foo)
const vm = app.mount()

await Vue.nextTick()
await nextTick()
expect(vm.$el.textContent).toBe('foobar')
})
})
2 changes: 2 additions & 0 deletions test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './mockWarn'
export * from './utils'
10 changes: 5 additions & 5 deletions test/misc.spec.js → test/misc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const Vue = require('vue/dist/vue.common.js')
const { ref, nextTick } = require('../src')
import Vue from './vue'
import { ref, nextTick } from '../src'

describe('nextTick', () => {
it('should works', () => {
const vm = new Vue({
it('should works with callbacks', () => {
const vm = new Vue<{ a: number }>({
template: `<div>{{a}}</div>`,
setup() {
return {
Expand All @@ -28,7 +28,7 @@ describe('nextTick', () => {
})

it('should works with await', async () => {
const vm = new Vue({
const vm = new Vue<{ a: number }>({
template: `<div>{{a}}</div>`,
setup() {
return {
Expand Down
4 changes: 2 additions & 2 deletions test/v3/reactivity/computed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
ref,
watchEffect,
WritableComputedRef,
nextTick,
} from '../../../src'
import { mockWarn } from '../../helpers/mockWarn'
import { nextTick } from '../../helpers/utils'
import { mockWarn } from '../../helpers'

describe('reactivity/computed', () => {
mockWarn(true)
Expand Down
2 changes: 1 addition & 1 deletion test/v3/runtime-core/apiLifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
onUpdated,
onBeforeUnmount,
onUnmounted,
nextTick,
} from '../../../src'
import { nextTick } from '../../helpers/utils'

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

Expand Down
3 changes: 1 addition & 2 deletions test/v3/runtime-core/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
ref,
set,
shallowReactive,
nextTick,
} from '../../../src'
import { nextTick } from '../../helpers/utils'
import Vue from 'vue'

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


// #388
it('should not call the callback multiple times', () => {
const data = ref([1, 1, 1, 1, 1])
Expand Down
8 changes: 8 additions & 0 deletions test/vue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// `vue.common.js` is required for shallow mounts.
// Typescript can not infer it properly, this file is a workround to set the type

// @ts-ignore
import _vue from 'vue/dist/vue.common'
import { VueConstructor } from 'vue'

export default (_vue as any) as VueConstructor

0 comments on commit aec2c26

Please sign in to comment.