Skip to content

Commit 65d61ed

Browse files
Added test cases
1 parent d9aa46b commit 65d61ed

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"enzyme": "^3.10.0",
24-
"enzyme-adapter-react-16": "^1.14.0"
24+
"enzyme-adapter-react-16": "^1.14.0",
25+
"redux-mock-store": "^1.5.3"
2526
}
2627
}

src/components/MatchesUserList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MatchesUserItem from './MatchesUserItem';
44
import {getMatchedUsers} from '../reduxStore/actions/userAction';
55
import {Redirect} from 'react-router-dom';
66

7-
class MatchesUserList extends Component{
7+
export class MatchesUserList extends Component{
88
constructor(props){
99
super(props);
1010
this.state={

src/components/tests/MatchesUserItem.test.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ import {matchsUsers} from './testing_data';
55

66
describe("MatchesUserItem tests", ()=>{
77
it("render users", ()=>{
8-
const users=matchsUsers.users;
9-
const wrapper=shallow(<MatchesUserItem user={users[0]} />);
8+
const user=matchsUsers.users[0];
9+
const wrapper=shallow(<MatchesUserItem user={user} />);
1010
expect(wrapper.find(".maches-user-item")).toBeDefined();
1111
expect(wrapper.find(".img-user-profile")).toBeDefined();
12-
})
12+
});
13+
it("render user details", ()=>{
14+
const user=matchsUsers.users[0];
15+
const wrapper=shallow(<MatchesUserItem user={user} />);
16+
expect(wrapper.contains(<div className="d-flex">
17+
<img className="img-user-profile" src={user.profile} alt="User Image" width="60px" height="60px"/>
18+
<div style={{marginLeft: '10px'}}>
19+
<label>y</label><br />
20+
<label>{user.location}</label>
21+
</div>
22+
</div>));
23+
});
24+
1325
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import {shallow} from '../../enzyme';
3+
import {matchsUsers} from './testing_data';
4+
import ConnectedMatchesUserList, {MatchesUserList} from '../MatchesUserList';
5+
import MatchesUserItem from '../MatchesUserItem';
6+
import { Provider } from "react-redux";
7+
import configureMockStore from "redux-mock-store";
8+
const mockStore = configureMockStore();
9+
10+
11+
describe("MatchesUserList tests", ()=>{
12+
const initialState = {userData: matchsUsers}
13+
let store, wrapper;
14+
beforeEach(()=>{
15+
store = mockStore(initialState)
16+
wrapper = shallow(<Provider store={store}>
17+
<ConnectedMatchesUserList />
18+
</Provider> )
19+
})
20+
it('+++ render the connected(SMART) component', () => {
21+
expect(wrapper.find(ConnectedMatchesUserList).length).toEqual(1)
22+
});
23+
24+
it('+++ check Prop matches with initialState', () => {
25+
expect(wrapper.find(MatchesUserList).prop('userData')).toEqual(initialState.userData)
26+
});
27+
})

0 commit comments

Comments
 (0)