Skip to content

Commit f9ab0fa

Browse files
authored
Merge pull request #52 from alexkrolick/examples-language-tabs
add code for different wrappers on query api page
2 parents 68b1ec4 + 356dbf4 commit f9ab0fa

File tree

10 files changed

+563
-122
lines changed

10 files changed

+563
-122
lines changed

.vscode/markdown.code-snippets

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
// Place your testing-library-docs workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3+
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4+
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5+
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6+
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
7+
// Placeholders with the same ids are connected.
8+
// Example:
9+
// "Print to console": {
10+
// "scope": "javascript,typescript",
11+
// "prefix": "log",
12+
// "body": [
13+
// "console.log('$1');",
14+
// "$2"
15+
// ],
16+
// "description": "Log output to console"
17+
// },
18+
"Multilanguage Code Block": {
19+
"scope": "markdown",
20+
"prefix": "docblock",
21+
"body": [
22+
"```html",
23+
"$4",
24+
"```",
25+
"",
26+
"<!--DOCUSAURUS_CODE_TABS-->",
27+
"",
28+
"<!--Native-->",
29+
"```js",
30+
"import { $1 } from 'dom-testing-library'",
31+
"",
32+
"const container = document.body",
33+
"const $3 = $1(container, '$2')",
34+
"```",
35+
"",
36+
"<!--React-->",
37+
"```js",
38+
"import { render } from 'react-testing-library'",
39+
"",
40+
"const { $1 } = render(<MyComponent />)",
41+
"const $3 = $1('$2')",
42+
"```",
43+
"",
44+
"<!--Cypress-->",
45+
"```js",
46+
"cy.$1('$2').should('exist')",
47+
"```",
48+
"",
49+
"<!--END_DOCUSAURUS_CODE_TABS-->"
50+
],
51+
"description": "Create a Docusaurus multi-language code block"
52+
}
53+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.rulers": [
3+
60, // try to keep examples this long
4+
80, // hard wrap
5+
]
6+
}

docs/api-configuration.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,35 @@ Configuration options:
1717

1818
`testIdAttribute`: The attribute used by `getByTestId` and related queries.
1919
Defaults to `data-testid`. See [`getByTestId`](#getbytestid).
20+
21+
```html
22+
23+
```
24+
25+
<!--DOCUSAURUS_CODE_TABS-->
26+
27+
<!--Native-->
28+
29+
```js
30+
// setup-tests.js
31+
import { configure } from 'dom-testing-library'
32+
33+
configure({testIdAttribute: 'my-data-test-id'})`
34+
```
35+
36+
<!--React-->
37+
38+
```js
39+
// setup-tests.js
40+
import { configure } from 'react-testing-library'
41+
42+
configure({testIdAttribute: 'my-data-test-id'})`
43+
```
44+
45+
<!--Cypress-->
46+
47+
```
48+
The configuration object is not currently exposed to in Cypress Testing Library
49+
```
50+
51+
<!--END_DOCUSAURUS_CODE_TABS-->

docs/api-helpers.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ module.exports = {
5050
}
5151
```
5252

53+
> **Note**
54+
>
55+
> Custom queries can be added to `react-testing-library`'s `render` method by
56+
> adding `queries` to the options config object. See the render
57+
> [options](/docs/react-testing-library/api#render-options).
58+
5359
### Using other assertion libraries
5460

5561
If you're not using jest, you may be able to find a similar set of custom
@@ -105,13 +111,37 @@ in use in `react-testing-library` and `vue-testing-library`.
105111
Example: To get the text 'hello' only within a section called 'messages', you
106112
could do:
107113

108-
```javascript
114+
<!--DOCUSAURUS_CODE_TABS-->
115+
116+
<!--Native-->
117+
118+
```js
109119
import { within } from 'dom-testing-library'
110120

111121
const { getByText } = within(document.getElementById('messages'))
112122
const helloMessage = getByText('hello')
113123
```
114124

125+
<!--React-->
126+
127+
```js
128+
import { render, within } from 'react-testing-library'
129+
130+
const { getByLabelText } = render(<MyComponent />)
131+
const signinModal = getByLabelText('Sign In')
132+
within(signinModal).getByPlaceholderText('Username')
133+
```
134+
135+
<!--Cypress-->
136+
137+
```js
138+
cy.get('form').within(() => {
139+
cy.getByText('Button Text').should('be.disabled')
140+
})
141+
```
142+
143+
<!--END_DOCUSAURUS_CODE_TABS-->
144+
115145
## Debugging
116146

117147
When you use any `get` calls in your test cases, the current state of the

0 commit comments

Comments
 (0)