-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: replace use of enzyme with react-testing-library #1144
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1144 +/- ##
==========================================
+ Coverage 46.22% 48.68% +2.46%
==========================================
Files 64 64
Lines 3003 3003
Branches 650 650
==========================================
+ Hits 1388 1462 +74
+ Misses 1363 1306 -57
+ Partials 252 235 -17
Continue to review full report at Codecov.
|
@ryan-m-walker ok so i merged the react 16 upgrade PR, so you'll just need to rebase it looks like? |
40aa663
to
e842329
Compare
@acao ok, I rebased |
@ryan-m-walker nice that was quick, thank you! |
e842329
to
785ac99
Compare
oh drat, i just merged the storybooks PR and so another conflict here |
@acao no worries, i'll try to fix later tonight |
@acao there's a minor change I want to make anyways |
785ac99
to
2a6e4d4
Compare
@acao should be good now |
96434cf
to
1c95b6d
Compare
- added @testing-library/react to graphiql package - added @testing-libary/jest-dom to graphiql package - removed usage of ENZYM env variable in test script in graphiql packaget - removed enzyme adapter setup from enzyme.config.js file and renamed it to test.config.js - removed use of enzyme and replaced with react-testing-library in all graphiql package test files and updated tests to use react-testing-library patterns - moved mockStorage to own file so it can be reused in other test files and added other methods to it - added a CodeMirror mock to be used in tests - mocked out codemirror addon modules - moved QueryHistory tests from own file into GraphiQL.spec.js file
1c95b6d
to
3c4ee46
Compare
@@ -0,0 +1,81 @@ | |||
export function MockCodeMirror(node, { value, ...options }) { | |||
let _eventListeners = {}; | |||
const mockTextArea = document.createElement('textarea'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters now but it may eventually, but our instantiation pattern for GraphiQL query editor is a bit different from the generic Codemirror example that tends to use<textarea />
.
We actually end up using a <section />
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we target a <section />
to instantiate CodeMirror but code mirror renders some more elements including a <textarea />
inside that root node:
they handle the typing and presentation in a pretty complex way it seems, where they use the type area as a temporary moving cursor and then render out typed text in some presentational elements. i figured for our testing purposes it'd just be easier to use a base text area and the abstracted mocked internals of CodeMirror for our testing purposes and keep the API our code interacts with the same. If you have a better idea let me know though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed yes! just pointing out there will be a subtle difference in the DOM hierarchy, but I think the only delta would be caused by container targets for full-height container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either way this is really great, and we can use this mock for codemirror-graphql I hope, which we still need to convert from mocha to jest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, yeah this might need some changes as we go. I already added a few more elements to the mock CodeMirror DOM in another PR that uses this branch as its base because it need to listen for click drag events on the gutter bar.
expect(W.find('MarkdownContent').text()).toEqual('No Description\n'); | ||
expect(W.find('TypeLink').text()).toEqual('String'); | ||
expect(W.find('Argument').length).toEqual(0); | ||
expect(container.querySelector('.doc-type-description')).toHaveTextContent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about how stable it will be using classes instead of component names as before, especially since we are about to change how layout/theming works and use theme-ui/emotion/etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm yeah, I wasn't to keen on using querySelector but I was trying to avoid making any changes to non-test code. Do you think it's worth adding either labels or testids to the components? We mostly just use a lot of classes in these components and react-testing-library doesn't let you target react implementation code
packages/graphiql/src/components/__tests__/helpers/codeMirror.js
Outdated
Show resolved
Hide resolved
- removed `cross-env` from test script - moved CodeMirror mock to __mock__ file
@testing-library/react
to graphiql package@testing-libary/jest-dom
to graphiql packageENZYME
env variable in test script in graphiql packagesenzyme.config.js
file and renamed itto
test.config.js
graphiql package test files and updated tests to use
react-testing-library patterns
and added other methods to it
completes: https://github.com/graphql/graphiql/projects/4#card-30693199
This PR gets rid off all uses of Enzyme in the GraphiQL package and replaces them with @testing-libary/react.