Skip to content

Commit 568e9ef

Browse files
committed
docs: ✏️ add byTestId DOM selector
1 parent 7b7039e commit 568e9ef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/docs/queries.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ spectator.query(byText('By text'));
4444
spectator.query(byText('By text', {selector: '#some .selector'}));
4545
spectator.query(byTextContent('By text content', {selector: '#some .selector'}));
4646
spectator.query(byRole('checkbox', { checked: true }));
47+
spectator.query(byTestId('someTestId'))
4748
```
4849

4950
The difference between `byText` and `byTextContent` is that the former doesn't match text inside a nested elements.
@@ -64,6 +65,14 @@ expect(byPlaceholder('Please enter your email address')).toHaveValue('my-value')
6465
// ... See the Custom Matchers section for a full list of possible matchers
6566
```
6667

68+
Configure `@testing-library/dom` to use `byTestId` with a different `testIdAttribute`
69+
70+
```ts
71+
import { configure } from '@testing-library/dom';
72+
73+
configure({ testIdAttribute: 'data-test' });
74+
```
75+
6776
### Parent Selector
6877
Spectator allows you to query for nested elements within a parent element. This is useful when you have multiple instances of the same component on the page and you want to query for children within a specific one. The parent selector is a string selector that is used to find the parent element. The parent selector is passed as the second parameter to the query methods. For example:
6978
```ts

0 commit comments

Comments
 (0)