From 9837a5424d3efeec366dd25fae77d4c938bd1c96 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Fri, 24 Apr 2020 09:49:24 +0200 Subject: [PATCH 1/3] repro: findComponent fails inside a Suspense --- tests/find.spec.ts | 1 - tests/findComponent.spec.ts | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/find.spec.ts b/tests/find.spec.ts index a4b51f147..6caab72a1 100644 --- a/tests/find.spec.ts +++ b/tests/find.spec.ts @@ -2,7 +2,6 @@ import { defineComponent, h } from 'vue' import { mount } from '../src' import SuspenseComponent from './components/Suspense.vue' -import Hello from './components/Hello.vue' describe('find', () => { it('find using single root node', () => { diff --git a/tests/findComponent.spec.ts b/tests/findComponent.spec.ts index 3f0da419c..72390234a 100644 --- a/tests/findComponent.spec.ts +++ b/tests/findComponent.spec.ts @@ -1,4 +1,4 @@ -import { defineComponent } from 'vue' +import { defineComponent, nextTick } from 'vue' import { mount } from '../src' import Hello from './components/Hello.vue' import ComponentWithoutName from './components/ComponentWithoutName.vue' @@ -112,6 +112,30 @@ describe('findComponent', () => { expect(wrapper.findComponent(compC).text()).toBe('C') }) + it('finds component in a Suspense', async () => { + const AsyncComponent = defineComponent({ + template: '{{ result }}', + async setup() { + return { result: 'Hello world' } + } + }) + const SuspenseComponent = defineComponent({ + template: ` + + + `, + components: { + AsyncComponent + } + }) + const wrapper = mount(SuspenseComponent) + expect(wrapper.html()).toContain('Loading') + await nextTick() + await nextTick() + expect(wrapper.html()).toContain('Hello world') + expect(wrapper.findComponent(AsyncComponent).text()).toBe('Hello world') + }) + it('finds a stub by name', () => { const wrapper = mount(compA, { global: { From a0a50629e7e66d38e3fbe6b172bf588ff43e9c47 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 24 Apr 2020 20:50:57 +1000 Subject: [PATCH 2/3] tests: add tests for teleport --- tests/findComponent.spec.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/findComponent.spec.ts b/tests/findComponent.spec.ts index 72390234a..1b02e025d 100644 --- a/tests/findComponent.spec.ts +++ b/tests/findComponent.spec.ts @@ -112,6 +112,27 @@ describe('findComponent', () => { expect(wrapper.findComponent(compC).text()).toBe('C') }) + it('finds component in a portal', async () => { + const Foo = { + name: 'Foo', + template: '
Foo
' + } + + const Comp = defineComponent({ + components: { Foo }, + template: ` +
+ + + + ` + }) + const wrapper = mount(Comp) + + expect(wrapper.find('#dest').text()).toContain('Foo') + expect(wrapper.findComponent({ name: 'Foo' }).text()).toContain('Foo') + }) + it('finds component in a Suspense', async () => { const AsyncComponent = defineComponent({ template: '{{ result }}', From b3af20d71ea66e67c196be9a9fa3da5d95be78aa Mon Sep 17 00:00:00 2001 From: dobromir-hristov Date: Sat, 25 Apr 2020 10:41:52 +0300 Subject: [PATCH 3/3] fix: find component in suspense --- src/utils/find.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/find.ts b/src/utils/find.ts index f89015c4a..54a9699ae 100644 --- a/src/utils/find.ts +++ b/src/utils/find.ts @@ -46,8 +46,12 @@ function findAllVNodes(vnode: VNode, selector: any): VNode[] { const nodes = [vnode] while (nodes.length) { const node = nodes.shift() + // match direct children aggregateChildren(nodes, node.children) + // match children of the wrapping component aggregateChildren(nodes, node.component?.subTree.children) + // match children if component is Suspense + aggregateChildren(nodes, node.suspense?.subTree.children) if (matches(node, selector)) { matchingNodes.push(node) }