Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 971c5c0

Browse files
committed
docs(readme): document function TextMatch closure limitation
1 parent 4ecf17d commit 971c5c0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,21 @@ Unique methods, not part of **@testing-library/dom**
330330
- Async utilities `waitForElement`, `waitForElementToBeRemoved` and `waitForDomChange` are not exposed. Consider using a `find*` query or a Playwright built-in like [`Locator.waitFor()`](https://playwright.dev/docs/api/class-locator#locator-wait-for).
331331
- The `fireEvent` method is not exposed, use Playwright's built-ins instead.
332332
- Assertion extensions from [**jest-dom**](https://testing-library.com/docs/ecosystem-jest-dom/) are not compatible, use Playwright Test if possible.
333-
- The [`getNodeText()`](https://testing-library.com/docs/dom-testing-library/api-custom-queries/#getnodetext) function is not currently supported for `Locator`.
333+
334+
### Locator Queries
335+
336+
- The [`getNodeText()`](https://testing-library.com/docs/dom-testing-library/api-custom-queries/#getnodetext) function is currently unsupported.
337+
- When using a function for [`TextMatch`](https://testing-library.com/docs/queries/about/#textmatch), the function cannot reference its closure scope
338+
339+
```ts
340+
// ✅ This is supported
341+
screen.getByText(content => content.startsWith('Foo'))
342+
343+
// ❌ This is not supported
344+
const startsWithFoo = (content: string) => content.startsWith('Foo')
345+
346+
screen.getByText(content => startsWithFoo(content))
347+
```
334348

335349
## Special Thanks
336350

0 commit comments

Comments
 (0)