Skip to content

Commit e49b788

Browse files
heatherKoo07Heather Koodevelopit
authored
Fix a bug in preact testing library usage example (#807)
Current example `expect(screen.textContent).toMatch("Current value: 6");` failed with the following error message expect(received).toMatch(expected) Matcher error: received value must be a string Received has value: undefined queries like getByText should be used to work with Async APIs like waitFor or findBy Co-authored-by: Heather Koo <[email protected]> Co-authored-by: Jason Miller <[email protected]>
1 parent 18b58b6 commit e49b788

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

content/en/guide/v10/preact-testing-library.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ describe('Counter', () => {
6666

6767
fireEvent.click(screen.getByText('Increment'));
6868
await waitFor(() => {
69-
expect(screen.textContent).toMatch('Current value: 6');
69+
// .toBeInTheDocument() is an assertion that comes from jest-dom.
70+
// Otherwise you could use .toBeDefined().
71+
expect(screen.getByText("Current value: 6")).toBeInTheDocument();
7072
});
7173
});
7274
});
@@ -80,7 +82,7 @@ test('should increment counter", async () => {
8082
8183
fireEvent.click(screen.getByText('Increment'));
8284
// WRONG: Preact likely won't have finished rendering here
83-
expect(screen.textContent).toMatch('Current value: 6');
85+
expect(screen.getByText("Current value: 6")).toBeInTheDocument();
8486
});
8587
```
8688

@@ -96,7 +98,7 @@ test('should increment counter", async () => {
9698
9799
await findByText('Current value: 6'); // waits for changed element
98100
99-
expect(screen.textContent).toMatch('Current value: 6'); // passes
101+
expect(screen.getByText("Current value: 6")).toBeInTheDocument(); // passes
100102
});
101103
```
102104

0 commit comments

Comments
 (0)