Skip to content

Commit 905d20b

Browse files
committed
tests was added
1 parent 2e40953 commit 905d20b

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

src/App.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { shallow } from 'enzyme';
12
import React from 'react';
2-
import { render } from '@testing-library/react';
33
import App from './App';
4-
5-
test('renders learn react link', () => {
6-
const { getByText } = render(<App />);
7-
const linkElement = getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
4+
import Adapter from 'enzyme-adapter-react-16';
5+
import { configure } from 'enzyme';
6+
configure({ adapter: new Adapter() });
7+
it("renders without crashing", () => {
8+
shallow(<App />);
99
});
10+
11+
it("renders Account header", () => {
12+
const wrapper = shallow(<App />);
13+
const welcome = <p></p>;
14+
expect(wrapper.contains(welcome)).toEqual(false);
15+
});

src/components/MockApi.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class MockApi {
1+
export default class MockApi {
22
constructor(defaultUsers = [], latency = 500) {
33
this.defaultUsers = defaultUsers;
44
this.latency = latency;
@@ -69,4 +69,3 @@ class MockApi {
6969
}
7070
}
7171

72-
export default MockApi;

src/components/MockApi.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Adapter from 'enzyme-adapter-react-16';
2+
import { configure, shallow } from 'enzyme';
3+
import { MockApi } from './MockApi';
4+
configure({ adapter: new Adapter() });
5+
6+
jest.mock('./MockApi', () => {
7+
// Works and lets you check for constructor calls:
8+
return {
9+
MockApi: jest.fn().mockImplementation(() => {
10+
return {
11+
getAllUSers: () => [],
12+
setUsers: () => undefined,
13+
};
14+
}),
15+
};
16+
});
17+
18+
beforeEach(() => {
19+
MockApi.mockClear();
20+
});
21+
22+
23+
24+
it('requires be an array to get all users method result', () => {
25+
const mockApi = new MockApi();
26+
expect(mockApi.getAllUSers()).toEqual([]);
27+
});
28+
29+
it('requires set users as an array', () => {
30+
const mockApi = new MockApi();
31+
expect(mockApi.setUsers()).toEqual(undefined);
32+
});
33+

src/components/Page.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { mount, shallow } from 'enzyme';
2+
import React from 'react';
3+
import Adapter from 'enzyme-adapter-react-16';
4+
import { configure } from 'enzyme';
5+
import Page from './Page';
6+
configure({ adapter: new Adapter() });
7+
8+
it('renders without crashing', () => {
9+
shallow(<Page><div></div></Page>)
10+
});
11+
12+
it('requires render with children', () => {
13+
const children = <p></p>;
14+
const wrapper = shallow(<Page>{children}</Page>);
15+
expect(wrapper.contains(children)).toEqual(true);
16+
});
17+
18+
it('requires contain children props', () => {
19+
const children = <p>this is children</p>;
20+
const wrapper = mount(<Page>{children}</Page>);
21+
expect(wrapper.props().children).toEqual(children);
22+
});

0 commit comments

Comments
 (0)