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

Commit addb123

Browse files
authored
test: clean up dirty tests and add app page component test (#71)
* test: refactor github organism test code with `.update()` This is a better workaround as opposed to comparing html output. enzymejs/enzyme#1233 * test: change github user highlight tests to `.update()` workaround * test: add unit tests for app page component
1 parent 4023dc1 commit addb123

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/organisms/github-user/github-user.test.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,27 @@ import UserMolecule from 'src/molecules/user';
44
import GithubUser from './github-user';
55
import highlights from './highlights';
66

7-
const data = {
8-
name: 'Cedric van Putten',
9-
login: 'byCedric',
10-
avatar_url: 'https://github.com/bycedric.png',
11-
bio: 'Lead developer @Peakfijn.',
12-
};
13-
147
describe('organisms/github-user/github-user', () => {
158
it('renders the user molecule component', async () => {
9+
const data = {
10+
name: 'Cedric van Putten',
11+
login: 'byCedric',
12+
avatar_url: 'https://github.com/bycedric.png',
13+
bio: 'Lead developer @Peakfijn.',
14+
};
15+
1616
const promise = Promise.resolve({ json: () => data });
1717

1818
global.fetch = jest.fn().mockReturnValue(promise);
1919

20-
const parentComponent = mount(<GithubUser />);
21-
const childComponent = mount(
22-
<UserMolecule
23-
name={data.name}
24-
username={data.login}
25-
avatarUrl={data.avatar_url}
26-
description={data.bio}
27-
highlights={highlights}
28-
/>
29-
);
30-
20+
const component = mount(<GithubUser />);
3121
await promise;
3222

33-
// because of the inline render function we can't use `.find()`
34-
expect(parentComponent.html()).toContain(childComponent.html());
23+
expect(component.update().find(UserMolecule))
24+
.toHaveProp('name', data.name)
25+
.toHaveProp('username', data.login)
26+
.toHaveProp('avatarUrl', data.avatar_url)
27+
.toHaveProp('description', data.bio)
28+
.toHaveProp('highlights', highlights);
3529
});
3630
});

src/organisms/github-user/highlights/keywords.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ describe('organisms/github-user/highlights/keyword', () => {
1313

1414
it('defines a (partial) decorator for "#" character', () => {
1515
const component = mount(
16-
HighlightKeyword.decorator['#']('match', 'text', '1337')
16+
HighlightKeyword.decorator['#']('match', 'text')
1717
);
1818

19-
expect(component).toHaveText('text');
19+
expect(component.update().find(HighlightKeyword))
20+
.toHaveProp('label', 'text');
2021
});
2122
});

src/organisms/github-user/highlights/mention.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ describe('organisms/github-user/highlights/mention', () => {
1919

2020
it('defines a (partial) decorator for "@" character', () => {
2121
const component = mount(
22-
HighlightMention.decorator['@']('match', 'text', '1337')
22+
HighlightMention.decorator['@']('match', 'text')
2323
);
2424

25-
expect(component.find('a'))
26-
.toHaveText('match')
27-
.toMatchSelector('[href="https://github.com/text"]');
25+
expect(component.update().find(HighlightMention))
26+
.toHaveProp('label', 'match')
27+
.toHaveProp('username', 'text');
2828
});
2929
});

src/pages/app/app.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import GithubUserOrganism from 'src/organisms/github-user';
4+
import App from './app';
5+
6+
describe('pages/app/app', () => {
7+
it('renders github organism component', () => {
8+
expect(shallow(<App />).find(GithubUserOrganism))
9+
.toExist();
10+
});
11+
});

0 commit comments

Comments
 (0)