Skip to content

Commit 8bec266

Browse files
committed
enzyme & co
1 parent d7bdd9a commit 8bec266

File tree

9 files changed

+79
-20
lines changed

9 files changed

+79
-20
lines changed

__mocks__/fileMock.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Created by invader on 18.10.16.
3+
*/
4+
5+
module.exports = 'test-file-stub';

__mocks__/styleMock.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Created by invader on 18.10.16.
3+
*/
4+
5+
module.exports = {};

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
"author": "Stdio.Digital",
3232
"license": "MIT",
3333
"homepage": "https://github.com/hex22a/post3ree-boilerplate#post3ree-boilerplate",
34+
"jest": {
35+
"verbose": true,
36+
"moduleNameMapper": {
37+
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
38+
"^.+\\.(css|less|pcss)$": "identity-obj-proxy"
39+
}
40+
},
3441
"devDependencies": {
3542
"autoprefixer": "^6.3.6",
3643
"babel": "^6.5.2",
@@ -56,8 +63,8 @@
5663
"cookie-parser": "^1.4.1",
5764
"css-loader": "^0.25.0",
5865
"css-modules-require-hook": "^4.0.2",
59-
"enzyme": "^2.4.1",
6066
"cucumber": "^1.3.1",
67+
"enzyme": "^2.4.1",
6168
"eslint": "^3.3.1",
6269
"eslint-config-airbnb-base": "^8.0.0",
6370
"eslint-loader": "^1.3.0",
@@ -70,6 +77,7 @@
7077
"file-loader": "^0.9.0",
7178
"history": "^4.3.0",
7279
"http": "0.0.0",
80+
"identity-obj-proxy": "^3.0.0",
7381
"image-webpack-loader": "^2.0.0",
7482
"immutable": "^3.7.6",
7583
"jest": "^16.0.1",
@@ -89,6 +97,7 @@
8997
"pug": "^2.0.0-beta5",
9098
"pug-html-loader": "^1.0.8",
9199
"react": "^15.3.1",
100+
"react-addons-test-utils": "^15.3.2",
92101
"react-datepicker": "^0.30.0",
93102
"react-dom": "^15.3.1",
94103
"react-hot-loader": "^3.0.0-beta.5",
@@ -100,6 +109,7 @@
100109
"redux-devtools-dock-monitor": "^1.1.0",
101110
"redux-devtools-log-monitor": "^1.0.4",
102111
"redux-logger": "^2.6.0",
112+
"redux-mock-store": "^1.2.1",
103113
"redux-thunk": "^2.1.0",
104114
"rethinkdb": "^2.2.2",
105115
"style-loader": "^0.13.0",
@@ -115,4 +125,4 @@
115125
"dependencies": {
116126
"forever": "^0.15.2"
117127
}
118-
}
128+
}

universal/containers/Main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { connect } from 'react-redux'
33

44
import './common/main.pcss'
55

6-
import ContainerWrapperHOC from './ContainerWrapper'
6+
import ContainerWrapperHOC from './ContainerWrapperHOC'
77
import Container from '../components/Container/Container'
88
import Menu from '../components/Menu/Menu'
99

10-
class Main extends Component {
10+
export class Main extends Component {
1111
render() {
1212
return (
1313
<Container>

universal/containers/SignIn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react'
22
import { connect } from 'react-redux'
33

4-
import ContainerWrapperHOC from './ContainerWrapper'
4+
import ContainerWrapperHOC from './ContainerWrapperHOC'
55
import Container from '../components/Container/Container'
66
import Menu from '../components/Menu/Menu'
77
import SignInForm from '../components/SignInForm/SignInForm'

universal/containers/SignUp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react'
22
import { connect } from 'react-redux'
33

4-
import ContainerWrapperHOC from './ContainerWrapper'
4+
import ContainerWrapperHOC from './ContainerWrapperHOC'
55
import Container from '../components/Container/Container'
66
import Menu from '../components/Menu/Menu'
77
import SignUpForm from '../components/SignUpForm/SignUpForm'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Created by invader on 18.10.16.
3+
*/
4+
5+
import React from 'react'
6+
import configureStore from 'redux-mock-store'
7+
import jest from 'jest'
8+
import { mount, shallow, ShallowWrapper } from 'enzyme'
9+
import ConnectedMain, { Main } from '../Main'
10+
11+
const mockStore = configureStore();
12+
13+
function setup() {
14+
const props = {
15+
isAuthenticated: false,
16+
payload: {
17+
sub: '',
18+
role: ''
19+
}
20+
};
21+
22+
const enzymeWrapper = shallow(<Main {...props} />);
23+
24+
return { props, enzymeWrapper }
25+
}
26+
27+
describe('Main container', () => {
28+
describe('descr', () => {
29+
const { enzymeWrapper } = setup();
30+
31+
it('Should render self and subcomponents', () => {
32+
expect(enzymeWrapper.find('div').isEmpty()).toBe(false)
33+
});
34+
});
35+
});

universal/reducers/__tests__/auth.test.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
import reducer from '../auth'
22
import * as constants from '../../actions/constants'
33

4+
const PAYLOAD = {
5+
uuid: 'jest@example.com',
6+
role: 'user'
7+
};
8+
49
describe('Auth reducers', () => {
510
describe('Auth', () => {
611
it('Should return the initial state', () => {
712
expect(reducer.auth(undefined, {})).toEqual({
813
isAuthenticated: false,
9-
role: ''
14+
payload: {
15+
sub: '',
16+
role: ''
17+
}
1018
});
1119
});
1220

1321
it('Should handle LOGIN_SUCCESS from user', () => {
1422
expect(reducer.auth({}, {
1523
type: constants.LOGIN_SUCCESS,
16-
role: 'user'
24+
payload: PAYLOAD
1725
})).toEqual({
1826
isAuthenticated: true,
19-
role: 'user'
27+
payload: {
28+
uuid: 'jest@example.com',
29+
role: 'user'
30+
}
2031
});
2132
});
2233

23-
it('Should handle LOGIN_SUCCESS from admin', () => {
24-
expect(reducer.auth({}, {
25-
type: constants.LOGIN_SUCCESS,
26-
role: 'admin'
27-
})).toEqual({
28-
isAuthenticated: true,
29-
role: 'admin'
30-
})
31-
});
32-
3334
it('Should handle LOGOUT_SUCCESS from any user', () => {
3435
expect(reducer.auth({}, {
3536
type: constants.LOGOUT_SUCCESS
3637
})).toEqual({
3738
isAuthenticated: false,
38-
role: ''
39+
payload: {
40+
sub: '',
41+
role: ''
42+
}
3943
})
4044
})
4145
});

0 commit comments

Comments
 (0)