Thanks to Max Stoiber for his blog
Note: I didnt get as successfull snapshot as followed from blog. So I tweaked it to make it work
| import React from "react"; | |
| import renderer from "react-test-renderer"; | |
| import { SignIn_Container } from "./signin_container"; | |
| import { getUserJobsList, signin } from "../../actions/"; | |
| describe("components", function() { | |
| describe("<SignIn_Container />", function() { | |
| it("renders correctly", function() { | |
| //took actions from actions needed in the component | |
| //took reducer values from initial state values in that reducer | |
| let props = { | |
| actions: { | |
| getUserJobsList: getUserJobsList, | |
| signin: signin | |
| }, | |
| session_reducer: { | |
| signedIn: false, | |
| showSignIn: false, | |
| error: false, | |
| userJobList: [], | |
| userJobListError: null, | |
| userDetails: {} | |
| } | |
| }; | |
| //I didnt find a way to test the component in complete isolation | |
| //until you pass the props which the component uses, we will get errors | |
| //TODO: need to find a generic way of tetsing without passing hardcoded actions, reducers | |
| let component = renderer | |
| .create( | |
| <SignIn_Container | |
| actions={props.actions} | |
| session_reducer={props.session_reducer} | |
| /> | |
| ) | |
| .toJSON(); | |
| expect(component).toMatchSnapshot(); | |
| }); | |
| }); | |
| }); |
Note: I didnt get as successfull snapshot as followed from blog. So I tweaked it to make it work