-
Notifications
You must be signed in to change notification settings - Fork 154
[WIP] Component unit tests using react-testing-library #339
[WIP] Component unit tests using react-testing-library #339
Conversation
@AWolf81, I started with tests for |
@idoberko2 Thanks for adding the Sidebar test. It looks OK but I'm getting an error message in every test - not sure why. It looks like following:
Seems like a configuration issue but I couldn't find the cause yet. |
|
||
const { getByText } = render(<Sidebar {...props} />); | ||
|
||
const projectButton = getByText(/Your new project was just added.*/); |
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.
getByText(/Your new project was just added.*/);
Is this supposed to be here? Is the parameter supposed to be in quotes?
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.
It looks a bit like a comment but it's a regex and there is more text in that element. So it's OK like it is.
Maybe the name of the constant shoud be introductionBlurb
so it's more clear that getByText
is querying it.
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.
Ah, gotcha :-) Yeah that works, or maybe just a comment above it explaining the regex (for people like me who see broken comments... 😅)
@@ -0,0 +1,61 @@ | |||
import React from 'react'; |
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.
Should the test files have this at the top? cc @AWolf81
/* eslint-disable flowtype/require-valid-file-annotation */
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 not sure. Do you want to avoid flow check for test files? I think // @flow
is just missing here.
I think we should also use flow in our tests or maybe we should ignore them in the flow configuration if we don't need type checking.
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.
Looks like only platform.service.test.js
and migrations.test.js
have // @flow
, rest are disabled. Maybe using Flow in the test files is not necessary?
I'm getting the From skimming over the code it seems like react-testing-library is much less verbose than Enzyme which I quite like. |
@AWolf81, @melanieseltzer, so what do you say? Should we drop |
@idoberko2 I think we should stick to Some other opinions to Testing-lib vs enzyme can be found in this DEV discussion. |
I'm going to agree and say let's stick with Enzyme for now :-) |
We can close this for now as the PR for Enzyme will be merged soon. Just waiting for the feedback from @idoberko2 to check if the Enzyme setup & the first tests are OK. |
Related Issue:
#309 -
react-testing-library
attemptSummary:
Examine the usage of
react-testing-library
to cover component testing