diff --git a/src/errorWrapper.ts b/src/errorWrapper.ts index fdbcae080..442dd0f30 100644 --- a/src/errorWrapper.ts +++ b/src/errorWrapper.ts @@ -4,6 +4,10 @@ export function createWrapperError( return new Proxy(Object.create(null), { get(obj, prop) { switch (prop) { + case 'then': + // allows for better errors when wrapping `find` in `await` + // https://github.com/vuejs/vue-test-utils-next/issues/638 + return case 'exists': return () => false default: diff --git a/tests/find.spec.ts b/tests/find.spec.ts index 862047dfe..8cddc0d81 100644 --- a/tests/find.spec.ts +++ b/tests/find.spec.ts @@ -1,6 +1,6 @@ -import { defineComponent, h } from 'vue' +import { defineComponent, h, nextTick } from 'vue' -import { mount } from '../src' +import { mount, VueWrapper } from '../src' import SuspenseComponent from './components/Suspense.vue' describe('find', () => { @@ -80,6 +80,25 @@ describe('find', () => { expect(wrapper.html()).toContain('Fallback content') expect(wrapper.find('div').exists()).toBeTruthy() }) + + test('can wrap `find` in an async function', async () => { + async function findAfterNextTick( + wrapper: VueWrapper, + selector: string + ) { + await nextTick() + return wrapper.find(selector) + } + + const wrapper = mount({ + template: `
My component
` + }) + const foundElement = await findAfterNextTick( + wrapper, + '.something-that-does-not-exist' + ) + expect(foundElement.exists()).toBeFalsy() + }) }) describe('findAll', () => {