From d2a39fea4bb64ff1e8c5362f91406d51c76dfc6a Mon Sep 17 00:00:00 2001 From: harunari Date: Sat, 4 Nov 2023 00:18:46 +0900 Subject: [PATCH] fix: wrapper.text method This change fixes wrapper.text to handle suspense components with comments in a slot. When suspense component had comments in a slot, wrapper.text returned empty. --- src/baseWrapper.ts | 2 +- tests/text.spec.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index a141d3a873..71f074bf5c 100644 --- a/src/baseWrapper.ts +++ b/src/baseWrapper.ts @@ -261,7 +261,7 @@ export default abstract class BaseWrapper } text() { - return textContent(this.element) + return this.getRootNodes().map(textContent).join('') } exists() { diff --git a/tests/text.spec.ts b/tests/text.spec.ts index a3a33387bc..8efb9d8aea 100644 --- a/tests/text.spec.ts +++ b/tests/text.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { defineComponent, h } from 'vue' +import { defineComponent, h, Suspense } from 'vue' import { mount } from '../src' @@ -93,4 +93,16 @@ describe('text', () => { const wrapper = mount(() => h(ReturnSlot, {}, () => h(MultiRootText))) expect(wrapper.text()).toBe('foobarbaz') }) + + it('returns correct text for suspense component with comments in a slot', () => { + const wrapper = mount({ + render: () => h(Suspense, {}, { + default: () => h(defineComponent({ + template: `
Text content
` + })) + }) + }) + + expect(wrapper.text()).toBe('Text content') + }) })