Skip to content

Commit 7cdc26d

Browse files
author
Kent C. Dodds
committed
fix(sel): match react native web's testID prop
Closes #1
1 parent 5c4659e commit 7cdc26d

File tree

7 files changed

+21
-21
lines changed

7 files changed

+21
-21
lines changed

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ components. It provides light utility functions on top of `react-dom` and
4444
* [`Simulate`](#simulate)
4545
* [`flushPromises`](#flushpromises)
4646
* [`render`](#render)
47-
* [More on `data-test` ids](#more-on-data-test-ids)
47+
* [More on `data-testid`s](#more-on-data-testids)
4848
* [FAQ](#faq)
4949
* [Other Solutions](#other-solutions)
5050
* [Guiding Principles](#guiding-principles)
@@ -128,16 +128,16 @@ The containing DOM node of your rendered React Element (rendered using
128128
129129
#### `queryByTestId`
130130

131-
A shortcut to `` container.querySelector(`[data-test="${yourId}"]`) ``. Read
132-
more about data-test ids below.
131+
A shortcut to `` container.querySelector(`[data-testid="${yourId}"]`) ``. Read
132+
more about `data-testid`s below.
133133

134134
```javascript
135135
const usernameInputElement = queryByTestId('username-input')
136136
```
137137

138-
## More on `data-test` ids
138+
## More on `data-testid`s
139139

140-
The `queryByTestId` utility is referring to the practice of using `data-test`
140+
The `queryByTestId` utility is referring to the practice of using `data-testid`
141141
attributes to identify individual elements in your rendered component. This is
142142
one of the practices this library is intended to encourage.
143143

@@ -216,18 +216,18 @@ something more
216216
Learn more about how Jest mocks work from my blog post:
217217
["But really, what is a JavaScript mock?"](https://blog.kentcdodds.com/but-really-what-is-a-javascript-mock-10d060966f7d)
218218

219-
**I don't want to use `data-test` attributes for everything. Do I have to?**
219+
**I don't want to use `data-testid` attributes for everything. Do I have to?**
220220

221-
Definitely not. That said, a common reason people don't like the `data-test`
221+
Definitely not. That said, a common reason people don't like the `data-testid`
222222
attribute is they're concerned about shipping that to production. I'd suggest
223223
that you probably want some simple E2E tests that run in production on occasion
224-
to make certain that things are working smoothly. In that case the `data-test`
224+
to make certain that things are working smoothly. In that case the `data-testid`
225225
attributes will be very useful. Even if you don't run these in production, you
226226
may want to run some E2E tests that run on the same code you're about to ship to
227-
production. In that case, the `data-test` attributes will be valuable there as
227+
production. In that case, the `data-testid` attributes will be valuable there as
228228
well.
229229

230-
All that said, if you really don't want to ship `data-test` attributes, then you
230+
All that said, if you really don't want to ship `data-testid` attributes, then you
231231
can use
232232
[this simple babel plugin](https://www.npmjs.com/package/babel-plugin-react-remove-properties)
233233
to remove them.

src/__tests__/__snapshots__/fetch.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
exports[`Fetch makes an API call and displays the greeting when load-greeting is clicked 1`] = `
44
<div>
55
<button
6-
data-test="load-greeting"
6+
data-testid="load-greeting"
77
>
88
Fetch
99
</button>
1010
<span
11-
data-test="greeting-text"
11+
data-testid="greeting-text"
1212
>
1313
hello there
1414
</span>

src/__tests__/fetch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class Fetch extends React.Component {
2020
const {data} = this.state
2121
return (
2222
<div>
23-
<button onClick={this.fetch} data-test="load-greeting">
23+
<button onClick={this.fetch} data-testid="load-greeting">
2424
Fetch
2525
</button>
26-
{data ? <span data-test="greeting-text">{data.greeting}</span> : null}
26+
{data ? <span data-testid="greeting-text">{data.greeting}</span> : null}
2727
</div>
2828
)
2929
}

src/__tests__/mock.react-transition-group.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class HiddenMessage extends React.Component {
1818
render() {
1919
return (
2020
<div>
21-
<button data-test="toggle-message" onClick={this.toggle}>
21+
<button data-testid="toggle-message" onClick={this.toggle}>
2222
Toggle
2323
</button>
2424
<Fade in={this.state.show}>
25-
<div data-test="hidden-message">Hello world</div>
25+
<div data-testid="hidden-message">Hello world</div>
2626
</Fade>
2727
</div>
2828
)

src/__tests__/number-display.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class NumberDisplay extends React.Component {
88
render() {
99
return (
1010
<div>
11-
<span data-test="number-display">{this.props.number}</span>
12-
<span data-test="instance-id">{this.id}</span>
11+
<span data-testid="number-display">{this.props.number}</span>
12+
<span data-testid="instance-id">{this.id}</span>
1313
</div>
1414
)
1515
}

src/__tests__/shallow.react-transition-group.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class HiddenMessage extends React.Component {
1818
render() {
1919
return (
2020
<div>
21-
<button data-test="toggle-message" onClick={this.toggle}>
21+
<button data-testid="toggle-message" onClick={this.toggle}>
2222
Toggle
2323
</button>
2424
<Fade in={this.state.show}>
25-
<div data-test="hidden-message">Hello world</div>
25+
<div data-testid="hidden-message">Hello world</div>
2626
</Fade>
2727
</div>
2828
)

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Simulate} from 'react-dom/test-utils'
33

44
// we may expose this eventually
55
function sel(id) {
6-
return `[data-test="${id}"]`
6+
return `[data-testid="${id}"]`
77
}
88

99
// we may expose this eventually

0 commit comments

Comments
 (0)