diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index a141d3a87..71f074bf5 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 a3a33387b..05e58b3db 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,24 @@ describe('text', () => { const wrapper = mount(() => h(ReturnSlot, {}, () => h(MultiRootText))) expect(wrapper.text()).toBe('foobarbaz') }) + + it('returns correct text for suspense component has multiple elements in a slot', () => { + const wrapper = mount({ + render: () => + h( + Suspense, + {}, + { + default: () => + h( + defineComponent({ + template: `
Text content
` + }) + ) + } + ) + }) + + expect(wrapper.text()).toBe('Text content') + }) })