Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsujat committed Oct 9, 2019
1 parent d6a9ab9 commit 42700be
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion react-context-api/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class App extends React.Component {

render() {
return (
<div>
<div data-testid="app">
<HeaderContainer />
<Switch>
<Route exact path="/" component={HomePage} />
Expand Down
27 changes: 27 additions & 0 deletions react-context-api/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { shallow } from "enzyme";
import { findByDataAttr, testStore } from "./utils/utils";
import App from "./App";

const setUp = (initialState = {}) => {
const store = testStore(initialState);
const wrapper = shallow(<App store={store}></App>)
.childAt(0)
.dive();
// console.log(wrapper.debug());
return wrapper;
};

describe("Render App Component Without Error", () => {
let wrapper;
beforeEach(() => {
const initialState = {
currentUser: {}
};
wrapper = setUp(initialState);
});
it("Should render without errors", () => {
const component = findByDataAttr(wrapper, "app");
expect(component.length).toBe(1);
});
});
20 changes: 10 additions & 10 deletions react-context-api/src/redux/root-reducer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { combineReducers } from 'redux';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { combineReducers } from "redux";
import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

import userReducer from './user/user.reducer';
import cartReducer from './cart/cart.reducer';
import directoryReducer from './directory/directory.reducer';
import shopReducer from './shop/shop.reducer';
import userReducer from "./user/user.reducer";
import cartReducer from "./cart/cart.reducer";
import directoryReducer from "./directory/directory.reducer";
import shopReducer from "./shop/shop.reducer";

const persistConfig = {
key: 'root',
key: "root",
storage,
whitelist: ['cart']
whitelist: ["cart"]
};

const rootReducer = combineReducers({
export const rootReducer = combineReducers({
user: userReducer,
cart: cartReducer,
directory: directoryReducer,
Expand Down
12 changes: 6 additions & 6 deletions react-context-api/src/redux/store.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createStore, applyMiddleware } from 'redux';
import { persistStore } from 'redux-persist';
import logger from 'redux-logger';
import { createStore, applyMiddleware } from "redux";
import { persistStore } from "redux-persist";
import logger from "redux-logger";

import rootReducer from './root-reducer';
import rootReducer from "./root-reducer";

const middlewares = [];
export const middlewares = [];

if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV === "development") {
middlewares.push(logger);
}

Expand Down

0 comments on commit 42700be

Please sign in to comment.