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
LCV container tests #809
LCV container tests #809
Conversation
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
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 have some questions about the changes to the LCV container component. I'm not sure about modifying the React lifecycle methods in order to get the tests to work.
If methods are modified to return a value then there should be a default return value, outside of any if
blocks, for consistency.
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
Could we have waiting until merging #810 until I had a chance to respond? |
We discussed potentially using the |
A few minutes of experimentation I've found that spying on I experimented with disabling the lifecycle methods and found that it worked for testing on waiting for a single promise to resolve, but not a chain of them. For example, my test for I really think returning the promise from One last approach could be flushing the promises, which I haven't tried yet: https://medium.com/@lucksp_22012/jest-enzyme-react-testing-with-async-componentdidmount-7c4c99e77d2d |
Should |
In #815 I'm splitting the viewer tests into |
If |
I'll give this approach a try. I can see your point about using a return for the other promise being inconsistent since it is within a conditional while making |
I'm going to update #815 to add |
This will be updated to use the improved error handling introduced in #815 |
Remove the spy on componentDidMount. Set a timeout instead, to wait for component state to update on mock subject load.
This is ready for review again. It's been updated to use the error handling in the subject viewer store. |
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Show resolved
Hide resolved
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 have some questions about changes to the error handling in the component itself. There's a couple of places where I think the code is catching errors then failing silently, where previously errors were logged to the console. I'm not sure if that's intended.
In the tests, you could stub the onReady
and onError
callbacks to check expectations and call done()
after they've run, which might make the code cleaner. That would guard against any cases where chained promises mean your initial promise resolves before the test has finished running.
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Show resolved
Hide resolved
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Show resolved
Hide resolved
@eatyourgreens I've tidied this up a bit. I think it's ready for review again. |
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 good to me. I think we've been talking at cross purposes about how try/catch works. I'm suggesting that requestData
should always return a value for rawData
. We've enforced consistent returns for functions in PFE, and I've got into the habit of looking for that in code.
If requestData
sometimes returns a data object, and sometimes an error or undefined, then that would be inconsistent and require more code to decide how to handle the return value, as you noted. My preference is to just keep the return type consistent for functions.
...Classifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.js
Outdated
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Show resolved
Hide resolved
...ifier/components/SubjectViewer/components/LightCurveViewer/LightCurveViewerContainer.spec.js
Outdated
Show resolved
Hide resolved
There was a stray |
Co-Authored-By: Jim O'Donnell <jim@eatyourgreens.org.uk>
@eatyourgreens this is ready for review again |
Package: lib-classifier
For #650
Describe your changes:
A first step toward the refactor by adding tests to the LCV container component. I plan on moving the store connection from the LCV to the LCV container and I want to make sure what is existing doesn't get broken in that process.
I have a single failing test that is a bit of a mystery to me at the moment. ItI figured out that I was missing a config for nock to work for multiple tests.calls the onReady prop on successful load
passes if isolated withonly
, but fails if run altogether with the block.Review Checklist
General
Apps
rm -rf node_modules/ && npm install
and app works as expected?