-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you rename data-testid
to data-test-id
because I am OCD?
#204
Comments
Please see testing-library/dom-testing-library#76 |
How about we allow for both |
Sorry, no. We're going to stick with what we have. You can create a custom query and pass it as an argument to dom-testing-library and use that one instead if you want. Thanks anyway! |
Would it be OK if I add a section in the README explaining how to make such a query? |
Yes, please do @Gpx! |
The example on the readme doesn't seem to work. // test-utils.js
import {render, queryHelpers} from 'react-testing-library'
export const queryByTestId = queryHelpers.queryByAttribute.bind(
null,
'data-test-id',
)
export const queryAllByTestId = queryHelpers.queryAllByAttribute.bind(
null,
'data-test-id',
)
export function getAllByTestId(container, id, ...rest) {
const els = queryAllByTestId(container, id, ...rest)
if (!els.length) {
throw getElementError(
`Unable to find an element by: [data-test-id="${id}"]`,
container,
)
}
return els
}
export function getByTestId(...args) {
return queryHelpers.firstResultOrNull(getAllByTestId, ...args)
}
const customRender = (node, ...options) => {
const utils = render(node, ...options)
return {
...utils,
getByTestId: getByTestId.bind(container),
getAllByTestId: getAllByTestId.bind(container),
queryByTestId: queryByTestId.bind(container),
queryAllByTestId: queryAllByTestId.bind(container),
}
}
// re-export everything
export * from 'react-testing-library'
// override render method
export {customRender as render} Here are the issues that I see:
|
Woops
PR appreciated |
Cool, I'll create a PR for this. |
This PR fixes the mistake in the custom renderer example as discussed on #204 (comment)
the ability has been added to the library, see here |
This PR fixes the mistake in the custom renderer example as discussed on testing-library/react-testing-library#204 (comment)
Not sure why we can't hyphenate the whole thing is all. 😄
The text was updated successfully, but these errors were encountered: