Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrapper.text method #2231

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/baseWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default abstract class BaseWrapper<ElementType extends Node>
}

text() {
return textContent(this.element)
return this.getRootNodes().map(textContent).join('')
}

exists() {
Expand Down
22 changes: 21 additions & 1 deletion tests/text.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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: `<!-- some comments --><div>Text content</div>`
})
)
}
)
})

expect(wrapper.text()).toBe('Text content')
})
})