Skip to content

Commit

Permalink
fix: better errors for async find (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 authored Jun 3, 2021
1 parent effcdc1 commit b0c1c66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/errorWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export function createWrapperError<T extends object>(
return new Proxy<T>(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:
Expand Down
23 changes: 21 additions & 2 deletions tests/find.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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<any>,
selector: string
) {
await nextTick()
return wrapper.find(selector)
}

const wrapper = mount({
template: `<div>My component</div>`
})
const foundElement = await findAfterNextTick(
wrapper,
'.something-that-does-not-exist'
)
expect(foundElement.exists()).toBeFalsy()
})
})

describe('findAll', () => {
Expand Down

0 comments on commit b0c1c66

Please sign in to comment.