Skip to content

Commit

Permalink
unit test and shanpshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsujat committed Oct 10, 2019
1 parent 42700be commit 7ae2320
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
9 changes: 8 additions & 1 deletion react-context-api/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ describe("Render App Component Without Error", () => {
let wrapper;
beforeEach(() => {
const initialState = {
currentUser: {}
user: {},
cart: [],
directory: [],
shop: []
};
wrapper = setUp(initialState);
});
it("Should render without errors", () => {
const component = findByDataAttr(wrapper, "app");
expect(component.length).toBe(1);
});
it("Should render App", () => {
const component = wrapper;
expect(component).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions react-context-api/src/__snapshots__/App.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Render App Component Without Error Should render App 1`] = `ShallowWrapper {}`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import "./checkout.styles.scss";
import CheckoutItemContainer from "../CheckoutItemContainer/CheckoutItemContainer";

const CheckoutPage = ({ cartItems, total }) => (
<div className="checkout-page">
const CheckoutContainer = ({ cartItems, total }) => (
<div className="checkout-page" data-testid="checkout-container">
<div className="checkout-header">
<div className="header-block">
<span>Product</span>
Expand Down Expand Up @@ -49,4 +49,4 @@ const mapStateToProps = createStructuredSelector({
total: selectCartTotal
});

export default connect(mapStateToProps)(CheckoutPage);
export default connect(mapStateToProps)(CheckoutContainer);
38 changes: 38 additions & 0 deletions react-context-api/src/redux/cart/cart.actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import CartActionTypes from "./cart.types";
import {
toggleCartHidden,
addItem,
removeItem,
clearItemFromCart
} from "./cart.actions";

it("should create an action to toggleCartHidden", () => {
const expectedAction = {
type: CartActionTypes.TOGGLE_CART_HIDDEN
};
expect(toggleCartHidden()).toEqual(expectedAction);
});
it("should create an action to addItem", () => {
const item = { id: 2, title: "test 2" };
const expectedAction = {
type: CartActionTypes.ADD_ITEM,
payload: item
};
expect(addItem(item)).toEqual(expectedAction);
});
it("should create an action to removeItem", () => {
const item = { id: 2, title: "test 2" };
const expectedAction = {
type: CartActionTypes.REMOVE_ITEM,
payload: item
};
expect(removeItem(item)).toEqual(expectedAction);
});
it("should create an action to clearItemFromCart", () => {
const item = { id: 2, title: "test 2" };
const expectedAction = {
type: CartActionTypes.CLEAR_ITEM_FROM_CART,
payload: item
};
expect(clearItemFromCart(item)).toEqual(expectedAction);
});
11 changes: 11 additions & 0 deletions react-context-api/src/redux/user/user.actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UserActionTypes } from "./user.types";
import { setCurrentUser } from "./user.actions";

it("should create an action to setCurrentUser", () => {
const user = { id: 2, email: "[email protected]" };
const expectedAction = {
type: UserActionTypes.SET_CURRENT_USER,
payload: user
};
expect(setCurrentUser(user)).toEqual(expectedAction);
});

0 comments on commit 7ae2320

Please sign in to comment.