Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 566556c

Browse files
committed
Refactor shallow render tests; Updated enzyme
Signed-off-by: Joe Lee <[email protected]>
1 parent c9031e2 commit 566556c

File tree

17 files changed

+236
-57
lines changed

17 files changed

+236
-57
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
*.iml
33
.idea/*
44
dist/*
5+
src/**/*.js

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@
2020
"@types/enzyme": "^2.7.7",
2121
"@types/jest": "19.2.2",
2222
"@types/react": "^15.0.21",
23-
"@types/react-addons-test-utils": "0.14.18",
2423
"@types/react-dom": "^15.5.0",
2524
"@types/react-redux": "^4.4.38",
26-
"@types/redux": "3.6.0",
2725
"@types/redux-actions": "^1.2.3",
2826
"@types/redux-logger": "^3.0.0",
2927
"awesome-typescript-loader": "^3.1.2",
3028
"cross-env": "4.0.0",
31-
"enzyme": "^2.8.0",
29+
"enzyme": "^2.8.2",
3230
"extract-text-webpack-plugin": "2.1.0",
3331
"html-webpack-plugin": "2.28.0",
3432
"jest": "^19.0.2",
3533
"karma": "^1.6.0",
3634
"karma-chrome-launcher": "^2.0.0",
3735
"karma-typescript": "^3.0.0",
3836
"karma-typescript-preprocessor": "^0.3.1",
39-
"react-addons-test-utils": "15.5.1",
4037
"react-hot-loader": "1.3.1",
38+
"react-test-renderer": "^15.5.4",
4139
"redux-actions": "2.0.2",
4240
"source-map-loader": "^0.2.1",
4341
"stylelint-webpack-plugin": "0.7.0",

src/Hello/__test__/actions.test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ReactDOM from "react-dom";
33
import {Provider, Store} from 'react-redux';
44

55
import configureStore from "./configureStore";
6-
import Hello from "./Hello/Hello";
6+
import Hello from "./main/components/Hello";
77

88
const store : Store<any> = configureStore();
99
ReactDOM.render(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {decrementAction, INCREMENT, incrementAction, DECREMENT} from "../actions";
2+
3+
describe("incrementAction", () => {
4+
it("returns action of type increment", () => {
5+
let action = {
6+
type: INCREMENT
7+
};
8+
expect(incrementAction()).toEqual(action);
9+
});
10+
});
11+
12+
describe("decrementAction", () => {
13+
it("returns action of type decrement", () => {
14+
let action = {
15+
type: DECREMENT
16+
};
17+
expect(decrementAction()).toEqual(action);
18+
});
19+
});

src/Hello/actions.ts renamed to src/main/actions/actions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import {createAction} from "redux-actions";
22

3-
export enum actionTypes {
4-
INCREMENT,
5-
DECREMENT
6-
}
3+
export const INCREMENT = "INCREMENT";
4+
export const DECREMENT = "DEVREMENT";
75

86
export const incrementAction : any = createAction<void>(
9-
actionTypes.INCREMENT.toString(),
7+
INCREMENT,
108
() => {
119
}
1210
);
1311

1412
export const decrementAction : any = createAction<void>(
15-
actionTypes.DECREMENT.toString(),
13+
DECREMENT,
1614
() => {
1715
}
1816
);

src/main/components/Counter.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var React = require("react");
4+
var Counter = function (props) {
5+
var counter = props.counter, increment = props.increment, decrement = props.decrement;
6+
return (<div>
7+
<p>Counter: {counter}</p>
8+
<button onClick={increment} label="Increment" id="increment"/>
9+
<button onClick={decrement} label="Decrement" id="decrement"/>
10+
</div>);
11+
};
12+
exports.default = Counter;

src/Hello/containers/Counter.tsx renamed to src/main/components/Counter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
22
import DefaultState from "../interfaces/defaultState"
33

4-
export interface IProps extends DefaultState {
4+
export interface CounterProps extends DefaultState {
55
increment(): void;
66
decrement(): void;
77
}
88

9-
const Counter = (props: IProps) => {
10-
const { counter, increment, decrement } = props;
9+
const Counter: any = (props: CounterProps) => {
10+
const {counter, increment, decrement} = props;
1111

1212
return (
1313
<div>

src/main/components/Hello.jsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || (function () {
3+
var extendStatics = Object.setPrototypeOf ||
4+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6+
return function (d, b) {
7+
extendStatics(d, b);
8+
function __() { this.constructor = d; }
9+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10+
};
11+
})();
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
var React = require("react");
14+
var react_redux_1 = require("react-redux");
15+
var redux_1 = require("redux");
16+
var Counter_1 = require("./Counter");
17+
var actions_1 = require("../actions/actions");
18+
var Hello = (function (_super) {
19+
__extends(Hello, _super);
20+
function Hello(props) {
21+
var _this = _super.call(this, props) || this;
22+
_this.increment = _this.increment.bind(_this);
23+
_this.decrement = _this.decrement.bind(_this);
24+
return _this;
25+
}
26+
Hello.prototype.increment = function () {
27+
this.props.actions.incrementAction();
28+
};
29+
Hello.prototype.decrement = function () {
30+
this.props.actions.decrementAction();
31+
};
32+
Hello.prototype.render = function () {
33+
return <div>
34+
<h1>Hello typescript and react!</h1>
35+
<Counter_1.default counter={this.props.counter} decrement={this.decrement} increment={this.increment}/>
36+
</div>;
37+
};
38+
return Hello;
39+
}(React.Component));
40+
exports.Hello = Hello;
41+
exports.mapStateToProps = function (state) {
42+
return state.counters;
43+
};
44+
exports.mapDispatchToProps = function (dispatch) {
45+
return {
46+
actions: redux_1.bindActionCreators(actions_1.default, dispatch)
47+
};
48+
};
49+
exports.default = react_redux_1.connect(exports.mapStateToProps, exports.mapDispatchToProps)(Hello);

src/Hello/Hello.tsx renamed to src/main/components/Hello.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as React from "react";
33
import {connect, Dispatch} from "react-redux";
44
import {bindActionCreators} from "redux";
55

6-
import Counter from "./containers/Counter";
7-
import {IRootState} from "../rootReducer";
8-
import actions from "./actions";
6+
import Counter from "./Counter";
7+
import {IRootState} from "../../rootReducer";
8+
import actions from "../actions/actions";
99

1010
export interface HelloProps {
1111
counter: number,

0 commit comments

Comments
 (0)