+ return {
+ bar: ref1,
+ }
+ },
+ template: `
`,
- components: {
- test: {
- id: 'test',
- template: '
test
',
+ components: {
+ test: {
+ id: 'test',
+ template: '
test
',
+ },
},
- },
- }).$mount()
- vm.$nextTick()
- .then(() => {
- expect(dummy).toBe(vm.$refs.bar)
- })
- .then(done)
- })
-
- it('should dynamically update refs', (done) => {
- const vm = new Vue({
- setup() {
- const ref1 = ref(null)
- const ref2 = ref(null)
- watchEffect(() => {
- dummy1 = ref1.value
- dummy2 = ref2.value
+ }).$mount()
+ vm.$nextTick()
+ .then(() => {
+ expect(dummy).toBe(vm.$refs.bar)
})
+ .then(done)
+ }))
- return {
- value: 'bar',
- bar: ref1,
- foo: ref2,
- }
- },
- template: '
',
- }).$mount()
- waitForUpdate(() => {})
- .then(() => {
- expect(dummy1).toBe(vm.$refs.bar)
- expect(dummy2).toBe(null)
- vm.value = 'foo'
- })
- .then(() => {
- // vm updated. ref update occures after updated;
- })
- .then(() => {
- // no render cycle, empty tick
- })
- .then(() => {
- expect(dummy1).toBe(null)
- expect(dummy2).toBe(vm.$refs.foo)
- })
- .then(done)
- })
+ it('should dynamically update refs', () =>
+ new Promise((done, reject) => {
+ done.fail = reject
+
+ let dummy1 = null
+ let dummy2 = null
+
+ const vm = new Vue({
+ setup() {
+ const ref1 = ref(null)
+ const ref2 = ref(null)
+ watchEffect(() => {
+ dummy1 = ref1.value
+ dummy2 = ref2.value
+ })
+
+ return {
+ value: 'bar',
+ bar: ref1,
+ foo: ref2,
+ }
+ },
+ template: '
',
+ }).$mount()
+ waitForUpdate(() => {})
+ .then(() => {
+ expect(dummy1).toBe(vm.$refs.bar)
+ expect(dummy2).toBe(null)
+ vm.value = 'foo'
+ })
+ .then(() => {
+ // vm updated. ref update occures after updated;
+ })
+ .then(() => {
+ // no render cycle, empty tick
+ })
+ .then(() => {
+ expect(dummy1).toBe(null)
+ expect(dummy2).toBe(vm.$refs.foo)
+ })
+ .then(done)
+ }))
// #296
it('should dynamically update refs in context', async () => {
diff --git a/test/use.spec.ts b/test/use.spec.ts
index 469e2f81..b375dbfb 100644
--- a/test/use.spec.ts
+++ b/test/use.spec.ts
@@ -25,7 +25,7 @@ describe('use', () => {
config: {
optionMergeStrategies: {},
},
- mixin: jest.fn(),
+ mixin: vi.fn(),
}
// @ts-ignore
diff --git a/test/v3/reactivity/computed.spec.ts b/test/v3/reactivity/computed.spec.ts
index 75517286..f903066b 100644
--- a/test/v3/reactivity/computed.spec.ts
+++ b/test/v3/reactivity/computed.spec.ts
@@ -23,7 +23,7 @@ describe('reactivity/computed', () => {
it('should compute lazily', () => {
const value = reactive<{ foo?: number }>({ foo: undefined })
- const getter = jest.fn(() => value.foo)
+ const getter = vi.fn(() => value.foo)
const cValue = computed(getter)
// lazy
@@ -77,8 +77,8 @@ describe('reactivity/computed', () => {
it('should trigger effect when chained', () => {
const value = reactive({ foo: 0 })
- const getter1 = jest.fn(() => value.foo)
- const getter2 = jest.fn(() => {
+ const getter1 = vi.fn(() => value.foo)
+ const getter2 = vi.fn(() => {
return c1.value + 1
})
const c1 = computed(getter1)
@@ -103,8 +103,8 @@ describe('reactivity/computed', () => {
it('should trigger effect when chained (mixed invocations)', async () => {
const value = reactive({ foo: 0 })
- const getter1 = jest.fn(() => value.foo)
- const getter2 = jest.fn(() => {
+ const getter1 = vi.fn(() => value.foo)
+ const getter2 = vi.fn(() => {
return c1.value + 1
})
const c1 = computed(getter1)
diff --git a/test/v3/reactivity/del.spec.ts b/test/v3/reactivity/del.spec.ts
index f590034e..490ce00d 100644
--- a/test/v3/reactivity/del.spec.ts
+++ b/test/v3/reactivity/del.spec.ts
@@ -6,7 +6,7 @@ describe('reactivity/del', () => {
const obj = reactive<{ a?: object }>({
a: {},
})
- const spy = jest.fn()
+ const spy = vi.fn()
watch(obj, spy, { deep: true, flush: 'sync' })
delete obj.a // Vue 2 limitation
expect(spy).not.toHaveBeenCalled()
@@ -17,7 +17,7 @@ describe('reactivity/del', () => {
const obj = reactive<{ a?: object }>({
a: {},
})
- const spy = jest.fn()
+ const spy = vi.fn()
watch(obj, spy, { deep: true, flush: 'sync' })
del(obj, 'a')
expect(spy).toBeCalledTimes(1)
@@ -26,7 +26,7 @@ describe('reactivity/del', () => {
it('should not remove element on array index and should not trigger reactivity', () => {
const arr = ref([1, 2, 3])
- const spy = jest.fn()
+ const spy = vi.fn()
watch(arr, spy, { flush: 'sync' })
delete arr.value[1] // Vue 2 limitation; workaround with .splice()
expect(spy).not.toHaveBeenCalled()
@@ -35,7 +35,7 @@ describe('reactivity/del', () => {
it('should trigger reactivity when using del on array', () => {
const arr = ref([1, 2, 3])
- const spy = jest.fn()
+ const spy = vi.fn()
watch(arr, spy, { flush: 'sync' })
del(arr.value, 1)
expect(spy).toBeCalledTimes(1)
@@ -45,9 +45,9 @@ describe('reactivity/del', () => {
it('should trigger reactivity when using del on array to delete index out of valid array length', () => {
const arr = ref
([])
const MAX_VALID_ARRAY_LENGTH = Math.pow(2, 32) - 1
- const NON_VALIDD_INDEX = MAX_VALID_ARRAY_LENGTH + 1
- set(arr.value, NON_VALIDD_INDEX, 0)
- const spy = jest.fn()
+ const NON_VALID_INDEX = MAX_VALID_ARRAY_LENGTH + 1
+ set(arr.value, NON_VALID_INDEX, 0)
+ const spy = vi.fn()
watchEffect(
() => {
spy(arr.value)
@@ -55,7 +55,7 @@ describe('reactivity/del', () => {
{ flush: 'sync' }
)
expect(spy).toBeCalledTimes(1)
- del(arr.value, NON_VALIDD_INDEX)
+ del(arr.value, NON_VALID_INDEX)
expect(spy).toBeCalledTimes(2)
})
})
diff --git a/test/v3/reactivity/effectScope.spec.ts b/test/v3/reactivity/effectScope.spec.ts
index f50a4b3f..decb8710 100644
--- a/test/v3/reactivity/effectScope.spec.ts
+++ b/test/v3/reactivity/effectScope.spec.ts
@@ -17,7 +17,7 @@ describe('reactivity/effect/scope', () => {
mockWarn(true)
it('should run', () => {
- const fnSpy = jest.fn(() => {})
+ const fnSpy = vi.fn(() => {})
new EffectScope().run(fnSpy)
expect(fnSpy).toHaveBeenCalledTimes(1)
})
@@ -132,7 +132,7 @@ describe('reactivity/effect/scope', () => {
await nextTick()
expect(dummy).toBe(7)
- // nested scope should not be stoped
+ // nested scope should not be stopped
expect(doubled).toBe(12)
})
@@ -210,7 +210,7 @@ describe('reactivity/effect/scope', () => {
})
it('should warn onScopeDispose() is called when there is no active effect scope', () => {
- const spy = jest.fn()
+ const spy = vi.fn()
const scope = new EffectScope()
scope.run(() => {
onScopeDispose(spy)
@@ -231,9 +231,9 @@ describe('reactivity/effect/scope', () => {
it('test with higher level APIs', async () => {
const r = ref(1)
- const computedSpy = jest.fn()
- const watchSpy = jest.fn()
- const watchEffectSpy = jest.fn()
+ const computedSpy = vi.fn()
+ const watchSpy = vi.fn()
+ const watchEffectSpy = vi.fn()
let c: ComputedRef
const scope = new EffectScope()
diff --git a/test/v3/reactivity/reactive.spec.ts b/test/v3/reactivity/reactive.spec.ts
index 19dbe534..af18d2d7 100644
--- a/test/v3/reactivity/reactive.spec.ts
+++ b/test/v3/reactivity/reactive.spec.ts
@@ -12,9 +12,9 @@ import {
} from '../../../src'
describe('reactivity/reactive', () => {
- let warn: jest.SpyInstance
+ let warn: vi.SpyInstance
beforeEach(() => {
- warn = jest.spyOn(global.console, 'error').mockImplementation(() => null)
+ warn = vi.spyOn(global.console, 'error').mockImplementation(() => null)
warn.mockReset()
})
afterEach(() => {
diff --git a/test/v3/reactivity/readonly.spec.ts b/test/v3/reactivity/readonly.spec.ts
index 8aa29ba6..2f371884 100644
--- a/test/v3/reactivity/readonly.spec.ts
+++ b/test/v3/reactivity/readonly.spec.ts
@@ -424,7 +424,7 @@ describe('reactivity/readonly', () => {
// #712
test('watch should work for ref with shallowReadonly', async () => {
- const cb = jest.fn()
+ const cb = vi.fn()
const vm = new Vue({
template: '{{ countRef }}
',
setup() {
@@ -452,7 +452,7 @@ describe('reactivity/readonly', () => {
// #712
test('watch should work for reactive with shallowReadonly', async () => {
- const cb = jest.fn()
+ const cb = vi.fn()
const vm = new Vue({
template: '{{ count.number }}
',
setup() {
diff --git a/test/v3/reactivity/set.spec.ts b/test/v3/reactivity/set.spec.ts
index d0a76072..c6522c08 100644
--- a/test/v3/reactivity/set.spec.ts
+++ b/test/v3/reactivity/set.spec.ts
@@ -3,7 +3,7 @@ import { set, reactive, ref, watch, watchEffect } from '../../../src'
describe('reactivity/set', () => {
it('should not trigger reactivity on native object member assignment', () => {
const obj = reactive<{ a?: number }>({})
- const spy = jest.fn()
+ const spy = vi.fn()
watch(obj, spy, { deep: true, flush: 'sync' })
obj.a = 1
expect(spy).not.toHaveBeenCalled()
@@ -12,7 +12,7 @@ describe('reactivity/set', () => {
it('should trigger reactivity when using set on reactive object', () => {
const obj = reactive<{ a?: number }>({})
- const spy = jest.fn()
+ const spy = vi.fn()
watch(obj, spy, { deep: true, flush: 'sync' })
set(obj, 'a', 1)
expect(spy).toBeCalledTimes(1)
@@ -21,7 +21,7 @@ describe('reactivity/set', () => {
it('should trigger watchEffect when using set to change value of array length', () => {
const arr = ref([1, 2, 3])
- const spy = jest.fn()
+ const spy = vi.fn()
watchEffect(
() => {
spy(arr.value)
diff --git a/test/v3/runtime-core/apiAsyncComponent.spec.ts b/test/v3/runtime-core/apiAsyncComponent.spec.ts
index 97f2941d..dbc54d04 100644
--- a/test/v3/runtime-core/apiAsyncComponent.spec.ts
+++ b/test/v3/runtime-core/apiAsyncComponent.spec.ts
@@ -151,7 +151,7 @@ describe('api: defineAsyncComponent', () => {
render: () => (toggle.value ? h(Foo) : null),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
@@ -200,7 +200,7 @@ describe('api: defineAsyncComponent', () => {
render: () => (toggle.value ? h(Foo) : null),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
@@ -247,7 +247,7 @@ describe('api: defineAsyncComponent', () => {
render: () => (toggle.value ? h(Foo) : null),
})
- jest.spyOn(global.console, 'error').mockImplementation(() => null)
+ vi.spyOn(global.console, 'error').mockImplementation(() => null)
const vm = app.mount()
expect(vm.$el.textContent).toBe('')
@@ -296,7 +296,7 @@ describe('api: defineAsyncComponent', () => {
render: () => (toggle.value ? h(Foo) : null),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
@@ -349,7 +349,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
@@ -384,7 +384,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
@@ -418,7 +418,7 @@ describe('api: defineAsyncComponent', () => {
const app = createApp({
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const vm = app.mount()
@@ -452,7 +452,7 @@ describe('api: defineAsyncComponent', () => {
const app = createApp({
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const vm = app.mount()
@@ -499,7 +499,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo),
})
- jest.spyOn(global.console, 'error').mockImplementation(() => null)
+ vi.spyOn(global.console, 'error').mockImplementation(() => null)
const vm = app.mount()
expect(vm.$el.textContent).toBe('')
@@ -543,7 +543,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const vm = app.mount()
@@ -584,7 +584,7 @@ describe('api: defineAsyncComponent', () => {
render: () => h(Foo),
})
- const handler = jest
+ const handler = vi
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const vm = app.mount()
diff --git a/test/v3/runtime-core/apiInject.spec.ts b/test/v3/runtime-core/apiInject.spec.ts
index 1ed7d5cb..99b7cc85 100644
--- a/test/v3/runtime-core/apiInject.spec.ts
+++ b/test/v3/runtime-core/apiInject.spec.ts
@@ -239,7 +239,7 @@ describe('api: provide/inject', () => {
const root = document.createElement('div')
const vm = createApp(Provider).mount(root)
expect(vm.$el.outerHTML).toBe(``)
- expect(`[Vue warn]: Injection "foo" not found`).toHaveBeenWarned()
+ expect(`[Vue warn]: Injection "foo" not found.`).toHaveBeenWarned()
})
it('should warn unfound w/ injectionKey is undefined', () => {
@@ -277,4 +277,31 @@ describe('api: provide/inject', () => {
const vm = createApp(Comp).mount(root)
expect(vm.$el.outerHTML).toBe(`foo
`)
})
+
+ it('should not warn when default value is undefined', () => {
+ const Provider = {
+ setup() {
+ provide('foo', undefined)
+ return () => h(Middle)
+ },
+ }
+
+ const Middle = {
+ setup() {
+ return () => h(Consumer)
+ },
+ }
+
+ const Consumer = {
+ setup() {
+ const foo = inject('foo')
+ return () => h('div', foo as unknown as string)
+ },
+ }
+
+ const root = document.createElement('div')
+ const vm = createApp(Provider).mount(root)
+ expect(vm.$el.outerHTML).toBe(``)
+ expect(`injection "foo" not found.`).not.toHaveBeenWarned()
+ })
})
diff --git a/test/v3/runtime-core/apiLifecycle.spec.ts b/test/v3/runtime-core/apiLifecycle.spec.ts
index b616d243..ac22a676 100644
--- a/test/v3/runtime-core/apiLifecycle.spec.ts
+++ b/test/v3/runtime-core/apiLifecycle.spec.ts
@@ -16,7 +16,7 @@ import {
describe('api: lifecycle hooks', () => {
it('onBeforeMount', () => {
const root = document.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is rendered
expect(root.innerHTML).toBe(``)
})
@@ -34,7 +34,7 @@ describe('api: lifecycle hooks', () => {
it('onMounted', () => {
const root = document.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called after inner div is rendered
expect(root.outerHTML).toBe(``)
})
@@ -53,7 +53,7 @@ describe('api: lifecycle hooks', () => {
it('onBeforeUpdate', async () => {
const count = ref(0)
// const root = document.createElement('div');
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is updated
expect(vm.$el.outerHTML).toBe(`0
`)
})
@@ -75,7 +75,7 @@ describe('api: lifecycle hooks', () => {
it('onUpdated', async () => {
const count = ref(0)
// const root = document.createElement('div');
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called after inner div is updated
expect(vm.$el.outerHTML).toBe(`1
`)
})
@@ -97,7 +97,7 @@ describe('api: lifecycle hooks', () => {
// it('onBeforeUnmount', async () => {
// const toggle = ref(true);
// const root = document.createElement('div');
- // const fn = jest.fn(() => {
+ // const fn = vi.fn(() => {
// // should be called before inner div is removed
// expect(root.outerHTML).toBe(``);
// });
@@ -126,7 +126,7 @@ describe('api: lifecycle hooks', () => {
// it('onUnmounted', async () => {
// const toggle = ref(true);
// const root = document.createElement('div');
- // const fn = jest.fn(() => {
+ // const fn = vi.fn(() => {
// // should be called after inner div is removed
// expect(root.outerHTML).toBe(``);
// });
@@ -155,7 +155,7 @@ describe('api: lifecycle hooks', () => {
it('onBeforeUnmount in onMounted', async () => {
const toggle = ref(true)
const root = document.createElement('div')
- const fn = jest.fn(() => {
+ const fn = vi.fn(() => {
// should be called before inner div is removed
expect(root.outerHTML).toBe(``)
})
@@ -274,7 +274,7 @@ describe('api: lifecycle hooks', () => {
// it('onRenderTracked', () => {
// const events: DebuggerEvent[] = [];
- // const onTrack = jest.fn((e: DebuggerEvent) => {
+ // const onTrack = vi.fn((e: DebuggerEvent) => {
// events.push(e);
// });
// const obj = reactive({ foo: 1, bar: 2 });
@@ -309,7 +309,7 @@ describe('api: lifecycle hooks', () => {
// it('onRenderTriggered', async () => {
// const events: DebuggerEvent[] = [];
- // const onTrigger = jest.fn((e: DebuggerEvent) => {
+ // const onTrigger = vi.fn((e: DebuggerEvent) => {
// events.push(e);
// });
// const obj = reactive({ foo: 1, bar: 2 });
diff --git a/test/v3/runtime-core/apiWatch.spec.ts b/test/v3/runtime-core/apiWatch.spec.ts
index b6825e0f..cd28dcb5 100644
--- a/test/v3/runtime-core/apiWatch.spec.ts
+++ b/test/v3/runtime-core/apiWatch.spec.ts
@@ -14,8 +14,8 @@ import { getRegisteredVueOrDefault } from '../../../src/runtimeContext'
describe('api: watch', () => {
const Vue = getRegisteredVueOrDefault()
- // const warnSpy = jest.spyOn(console, 'warn');
- const warnSpy = jest.spyOn((Vue as any).util, 'warn')
+ // const warnSpy = vi.spyOn(console, 'warn');
+ const warnSpy = vi.spyOn((Vue as any).util, 'warn')
beforeEach(() => {
warnSpy.mockReset()
@@ -143,7 +143,7 @@ describe('api: watch', () => {
const status = ref(false)
let dummy
- watch([() => state.count, status], (vals, oldVals) => {
+ watch([() => state.count, status] as const, (vals, oldVals) => {
dummy = [vals, oldVals]
const [count] = vals
const [, oldStatus] = oldVals
@@ -208,7 +208,7 @@ describe('api: watch', () => {
it('cleanup registration (effect)', async () => {
const state = reactive({ count: 0 })
- const cleanup = jest.fn()
+ const cleanup = vi.fn()
let dummy
const stop = watchEffect((onCleanup) => {
onCleanup(cleanup)
@@ -227,7 +227,7 @@ describe('api: watch', () => {
it('cleanup registration (with source)', async () => {
const count = ref(0)
- const cleanup = jest.fn()
+ const cleanup = vi.fn()
let dummy
const stop = watch(count, (count, prevCount, onCleanup) => {
onCleanup(cleanup)
@@ -251,7 +251,7 @@ describe('api: watch', () => {
// it('flush timing: post (default)', async () => {
// const count = ref(0);
// let callCount = 0;
- // const assertion = jest.fn(count => {
+ // const assertion = vi.fn(count => {
// callCount++;
// // on mount, the watcher callback should be called before DOM render
// // on update, should be called after the count is updated
@@ -281,7 +281,7 @@ describe('api: watch', () => {
// const count2 = ref(0);
// let callCount = 0;
- // const assertion = jest.fn((count, count2Value) => {
+ // const assertion = vi.fn((count, count2Value) => {
// callCount++;
// // on mount, the watcher callback should be called before DOM render
// // on update, should be called before the count is updated
@@ -322,7 +322,7 @@ describe('api: watch', () => {
// const count2 = ref(0);
// let callCount = 0;
- // const assertion = jest.fn(count => {
+ // const assertion = vi.fn(count => {
// callCount++;
// // on mount, the watcher callback should be called before DOM render
// // on update, should be called before the count is updated
@@ -408,7 +408,7 @@ describe('api: watch', () => {
it('immediate', async () => {
const count = ref(0)
- const cb = jest.fn()
+ const cb = vi.fn()
watch(count, cb, { immediate: true })
expect(cb).toHaveBeenCalledTimes(1)
count.value++
@@ -418,14 +418,14 @@ describe('api: watch', () => {
it('immediate: triggers when initial value is null', async () => {
const state = ref(null)
- const spy = jest.fn()
+ const spy = vi.fn()
watch(() => state.value, spy, { immediate: true })
expect(spy).toHaveBeenCalled()
})
it('immediate: triggers when initial value is undefined', async () => {
const state = ref()
- const spy = jest.fn()
+ const spy = vi.fn()
watch(() => state.value, spy, { immediate: true })
expect(spy).toHaveBeenCalled()
state.value = 3
@@ -500,7 +500,7 @@ describe('api: watch', () => {
// it('warn and not respect deep option when using effect', async () => {
// const arr = ref([1, [2]]);
- // const spy = jest.fn();
+ // const spy = vi.fn();
// watchEffect(
// () => {
// spy();
@@ -577,7 +577,7 @@ describe('api: watch', () => {
// #805 #807
it('watching sources: [ref<[]>] w/ deep', async () => {
const foo = ref([1])
- const cb = jest.fn()
+ const cb = vi.fn()
watch([foo], cb, { deep: true })
foo.value.push(2)
await nextTick()
diff --git a/test/v3/runtime-core/h.spec.ts b/test/v3/runtime-core/h.spec.ts
index 1a551a95..a5d17454 100644
--- a/test/v3/runtime-core/h.spec.ts
+++ b/test/v3/runtime-core/h.spec.ts
@@ -1,5 +1,5 @@
-import { h, createApp } from '../../../src'
-import { mockWarn } from '../../helpers'
+import { h, createApp, ref, getCurrentInstance } from '../../../src'
+import { mockWarn, sleep } from '../../helpers'
describe('renderer: h', () => {
mockWarn(true)
@@ -10,6 +10,45 @@ describe('renderer: h', () => {
).toHaveBeenWarned()
})
+ it('should not warn with called outside of render function', async () => {
+ const spy = vi.fn()
+ const Comp = {
+ setup() {
+ const instance = getCurrentInstance()
+ const createElement = h.bind(instance)
+ const renderVnode = () => createElement('p', {})
+ setTimeout(renderVnode, 10)
+ },
+ }
+ const root = document.createElement('div')
+ createApp(Comp).mount(root)
+ await sleep(50)
+
+ expect(spy).toHaveBeenCalledTimes(0)
+ })
+
+ it(`Should support h's responsive rendering`, async () => {
+ const Comp = {
+ setup() {
+ const showNode1 = ref(true)
+ setTimeout(() => {
+ showNode1.value = false
+ }, 10)
+ return () =>
+ showNode1.value
+ ? h('div', void 0, [h('br'), 'hello world', h('br')])
+ : h('div', void 0, [h('div'), 'nextTick render', h('div')])
+ },
+ }
+ const root = document.createElement('div')
+ const vm = createApp(Comp).mount(root)
+ expect(vm.$el.outerHTML).toBe(`
hello world
`)
+ await sleep(50)
+ expect(vm.$el.outerHTML).toBe(
+ ``
+ )
+ })
+
it('should work with called outside of render function', () => {
const msg = 'hello world'
const vnode = h('hello-world', {
diff --git a/test/vitest.setup.js b/test/vitest.setup.js
new file mode 100644
index 00000000..9c88c0b8
--- /dev/null
+++ b/test/vitest.setup.js
@@ -0,0 +1,14 @@
+import Vue from 'vue/dist/vue.common'
+import FullVue from 'vue/dist/vue.runtime.common'
+import plugin from '../src'
+import { waitForUpdate } from './helpers/wait-for-update'
+
+FullVue.config.productionTip = false
+FullVue.config.devtools = false
+Vue.config.productionTip = false
+Vue.config.devtools = false
+Vue.use(plugin)
+
+if (!global.waitForUpdate) {
+ global.waitForUpdate = waitForUpdate
+}
diff --git a/test/vue.ts b/test/vue.ts
index a81d1551..bdbb802f 100644
--- a/test/vue.ts
+++ b/test/vue.ts
@@ -1,5 +1,5 @@
// `vue.common.js` is required for shallow mounts.
-// Typescript can not infer it properly, this file is a workround to set the type
+// Typescript can not infer it properly, this file is a workaround to set the type
// @ts-ignore
import _vue from 'vue/dist/vue.common'
diff --git a/tsconfig.json b/tsconfig.json
index ac0f7f33..f79735fb 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es5",
"lib": ["dom", "esnext"],
+ "types": ["vitest/globals"],
"module": "esnext",
"moduleResolution": "node",
"skipLibCheck": true,
@@ -19,5 +20,5 @@
"downlevelIteration": true,
"noUnusedLocals": true
},
- "include": ["src"]
+ "include": ["src", "test", "test-dts"]
}
diff --git a/vitest.config.ts b/vitest.config.ts
new file mode 100644
index 00000000..84ebc53e
--- /dev/null
+++ b/vitest.config.ts
@@ -0,0 +1,16 @@
+import { defineConfig } from 'vitest/config'
+
+export default defineConfig({
+ test: {
+ watch: false,
+ globals: true,
+ setupFiles: ['./test/vitest.setup.js'],
+ include: ['./test/**/*.spec.{js,ts}'],
+ environment: 'jsdom',
+ },
+ define: {
+ __DEV__: true,
+ __VERSION__: true,
+ _refBrand: true,
+ },
+})