Open maksimgm opened 5 years ago
enzyme doesn't have any snapshot support, nor do we endorse snapshot testing at all.
Is the output of wrapper.debug()
unexpected?
Thank you for replying @ljharb. I meant Jest snapshot testing. That's good to know(regarding not endorsing snapshot testing), considering most of the jest
and enzyme
tutorials that I've watched start off their tests by creating a snapshot.
The output is unexpected:
<Connect(AnalyzeModal) store={{...}}>
<AnalyzeModal store={{...}} isOpen={false} id="" wasClicked={false} isSpinner={false} data=
{{...}} closeModal={[Function]} openModal={[Function]} sendData={[Function]} toggleMark=
{[Function]} toggleSpinner={[Function]} />
</Connect(AnalyzeModal)>
I expect the AnalyzeModal
to be output as displayed in my code, but for some reason it is returning the methods and props related to the component, but not the jsx itself.
You can try wrapper.debug({ verbose: true })
; but specifically that shows what your component renders, not necessarily the jsx you typed.
There is no difference in wrapper.debug({ verbose: true })
v. wrapper.debug()
. From the few articles that I read about modal testing with enzyme, it seems like the isOpen
property needs to be set to true
. I set that boolean, but it didn't change that was logged. This is what I am referencing:
-https://remarkablemark.org/blog/2017/05/17/testing-react-modal/ -https://github.com/reactjs/react-modal/issues/563
Certainly if one of the components will choose not to render its children absent isOpen
being true
, then they wouldn't show up.
isOpen
is set to true
and the output is the same
@maksimgm could you perhaps provide a codepen or repo that i could use to reproduce this problem? I'm not sure how to help here, otherwise.
try import { AnalyzeModal } from '../components/AnalyzeModal';
and pass whatever props should be there. I think you don't want to test redux functionality, just your component
I have a test for a React component which is being exported with
connect
. I was able to have my tests pass, but my Snapsnot is not what I expect it to be.My Component
note I took out some of the methods, since they are not applicable to the issue.
My Test
My Test Snapshot
Current behavior
Currently, the snapshot is returning the component without the JSX inside of the component itself.
Expected behavior
I expect the component to container jsx elements such as:
button
,div
, etc.Your environment
API
Version
Adapter