-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mixing custom render with all other exports gives error #169
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
Comments
Hmmm... It seems to be working fine for me here: https://github.com/kentcdodds/jest-cypress-react-babel-webpack/blob/master/test/calculator-test-utils.js |
Hmm, but you're not doing exactly the same, so maybe your way is the answer. You're renaming the lib |
Does this work instead? #170 |
As a temporary fix, similar to the README example, instead of overwriting import {customRender} from '../test-utils';
test('<Button/> opens modal', () => {
const {queryByText} = customRender(
<Button/>
)
// rest of the test...
} |
I'm guessing the issue is something to do with versions of babel or something. In any case I don't see anything actionable here. If someone discovers what's going on feel free to open a PR to improve the docs. |
I think it has to do with Babel 7 vs. 6. https://github.com/kentcdodds/jest-cypress-react-babel-webpack/blob/master/package.json is using v7. I'm getting the error on v6. |
https://github.com/babel/babel-upgrade try running this to upgrade to 7. Not quite working on my project but on a simpler config it should confirm whether or not this is the issue. |
<!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: <!-- Why are these changes necessary? --> **Why**: <!-- How were these changes implemented? --> **How**: <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> - [ ] Documentation - [ ] Tests - [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> - [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments -->
…brary#169) * feat(queryByCurrentValue): add get/query by current value * feat(queryByCurrentValue): exports (query|get)AllByCurrentValue * chore: change the order of exports * fix: add implementation for `select` element at `queryAllByCurrentValue` * chore: add tests for get/queryByCurrentValue * chore: add test for getAllByCurrentValue to throw * chore: rename xxxByCurrentValue -> xxxByDisplayValue * docs: add `getByDisplayValue` * docs: add `eunjae-lee` as a contributor * docs: remove `getByAltText`, `getByTitle` and `getByValue` * docs: update `getByDisplayValue` * chore: add test for 100% coverage * docs: remove unnecessary `console.log(...)` * Revert "docs: remove `getByAltText`, `getByTitle` and `getByValue`" This reverts commit c960865af18f2ecc81a6770806eef95cc7dd89f7. * docs: remove `getBySelectText` and `getByValue` * docs: update description on `getByDisplayName`
For anyone using TypeScript and running into the error
Ref: https://testing-library.com/docs/react-testing-library/setup |
I just paste the workaround solution from https://github.com/testing-library/react-testing-library/pull/179/files here in case you are googling by the error message. The root cause is believed caused by Babel version < 7 // test-utils.js
const rtl = require('react-testing-library')
const customRender = (node, ...options) => {
return rtl.render(<Something>{node}</Something>)
}
module.exports = {
...rtl,
render: customRender,
} |
@radihuq Thanks for pointing that out. For future reference, the error in my case was the following: |
Using the custom utils file as described in the README where you re-export everything from
react-testing-library
and override the render method gives the following error:TypeError: Cannot set property render of [object Object] which has only a getter
react-testing-library
version:5.0.1
react
version:16.5.0
node
version:10.0.0
npm
(oryarn
) version:1.6.0
Relevant code or config:
This is on
create-react-app
by the way (react-scripts@1.1.5
)The text was updated successfully, but these errors were encountered: