Skip to content

Instantly share code, notes, and snippets.

@sriramrudraraju
Last active November 2, 2017 16:47
Show Gist options
  • Select an option

  • Save sriramrudraraju/99161c1f4c1562600a5498ecc51d3d37 to your computer and use it in GitHub Desktop.

Select an option

Save sriramrudraraju/99161c1f4c1562600a5498ecc51d3d37 to your computer and use it in GitHub Desktop.
React Redux Unit Testing with Jest part 3: Components
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();
});
});
});

React Redux Unit Testing: Part 3

Example for Components using jest

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment