Skip to content

Commit

Permalink
Tech - React Test Library - Test Complete App
Browse files Browse the repository at this point in the history
  • Loading branch information
prabaprakash committed Sep 28, 2018
1 parent 850911c commit 5b770ee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"node-sass": "^4.9.3",
"nyc": "^12.0.2",
"react-addons-test-utils": "^15.6.2",
"react-testing-library": "^5.1.0",
"redux-test-utils": "^0.2.2",
"sass-loader": "^7.1.0",
"selenium-server": "^3.14.0",
Expand Down
1 change: 1 addition & 0 deletions src/client/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class App extends React.Component {
+
</Button>
<FormControl
data-testid="number"
type="text"
value={this.props.number}
onChange={this.handleChange}
Expand Down
42 changes: 42 additions & 0 deletions test/unit/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, it } from "mocha";
import { expect } from "chai";

import React from "react";
import ReactDOM from "react-dom";
import { render, fireEvent, cleanup } from "react-testing-library";
import { Provider, connect } from "react-redux";
import { createStore, applyMiddleware, compose } from "redux";
import createSagaMiddleware from "redux-saga";
const sagaMiddleware = createSagaMiddleware();

import reducers from "../../../src/client/reducers/combined";
import AppContainer from "../../../src/client/containers/App";
import rootSaga from "../../../src/client/sagas/combined";

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;


function renderWithRedux(ui, store) {
return {
...render(<Provider store={store}>{ui}</Provider>),
store
};
}

describe.only("actions", () => {
it("should trigger the ADD action", () => {
const store = createStore(
reducers,
{
calc: { number: 0 }
},
composeEnhancers(applyMiddleware(sagaMiddleware))
);
store.subscribe(()=> console.log(store.getState()));
sagaMiddleware.run(rootSaga);
const { getByTestId, getByText, getByValue } = renderWithRedux(<AppContainer />, store);
fireEvent.click(getByText("-"));
fireEvent.click(getByText("+"));
expect(getByTestId("number").value).to.equal("0");
});
});

0 comments on commit 5b770ee

Please sign in to comment.