Skip to content

Commit 5446fb5

Browse files
committed
Additional unit tests
1 parent f1de1f5 commit 5446fb5

File tree

9 files changed

+101
-4
lines changed

9 files changed

+101
-4
lines changed

__tests__/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as exports from '../src';
2+
3+
test('Exports expected stuff', () => {
4+
expect(exports).toHaveProperty('Avatar');
5+
expect(exports).toHaveProperty('Button');
6+
expect(exports).toHaveProperty('Link');
7+
expect(exports).toHaveProperty('NavLink');
8+
expect(exports).toHaveProperty('ScalableRect');
9+
});

__tests__/shared/GenericLink.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global window */
1+
/* global document, window */
22

33
import GenericLink from 'components/GenericLink';
44
import PT from 'prop-types';
@@ -65,15 +65,18 @@ test('onClick(..) works when rendered as custom <Link>', () => {
6565
simulate.click(link);
6666
expect(clickHandler).toHaveBeenCalled();
6767

68+
const domain = 'https://some.domain.com';
69+
document.location.assign = jest.fn();
6870
doc = renderDom((
6971
<GenericLink
7072
className="LINK"
7173
routerLinkType={Link}
72-
to="https://some.domain.com"
74+
to={domain}
7375
>LINK</GenericLink>
7476
));
7577
link = findInDomByClass(doc, 'LINK');
7678
simulate.click(link);
7779

80+
expect(document.location.assign).toHaveBeenCalledWith(domain);
7881
expect(window.scroll).toHaveBeenCalledTimes(1);
7982
});

__tests__/shared/Link.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Link from 'components/Link';
2+
import React from 'react';
3+
import { shallowSnapshot } from 'utils/jest';
4+
5+
test('Matches snapshots', () => {
6+
shallowSnapshot((
7+
<Link />
8+
));
9+
});

__tests__/shared/NavLink.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import NavLink from 'components/NavLink';
2+
import React from 'react';
3+
import { shallowRender } from 'utils/jest';
4+
5+
test('Matches snapshots', () => {
6+
shallowRender(<NavLink />);
7+
});

__tests__/shared/ScalableRect.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ScalableRect from 'components/ScalableRect';
2+
import React from 'react';
3+
import { snapshot } from 'utils/jest';
4+
5+
test('Snapshots match', () => {
6+
snapshot(<ScalableRect>CONTENT</ScalableRect>);
7+
snapshot((
8+
<ScalableRect
9+
className="CLASS_NAME"
10+
>CONTENT</ScalableRect>
11+
));
12+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Matches snapshots 1`] = `
4+
<GenericLink
5+
className={null}
6+
enforceA={false}
7+
onClick={null}
8+
onMouseDown={null}
9+
openNewTab={false}
10+
replace={false}
11+
routerLinkType={[Function]}
12+
to=""
13+
/>
14+
`;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Snapshots match 1`] = `
4+
<div
5+
className="src-shared-components-ScalableRect-___style__container___3YhfN"
6+
style={
7+
Object {
8+
"paddingBottom": "100%",
9+
}
10+
}
11+
>
12+
<div
13+
className="src-shared-components-ScalableRect-___style__wrapper___3qZoW"
14+
>
15+
CONTENT
16+
</div>
17+
</div>
18+
`;
19+
20+
exports[`Snapshots match 2`] = `
21+
<div
22+
className="CLASS_NAME"
23+
>
24+
<div
25+
className="src-shared-components-ScalableRect-___style__container___3YhfN"
26+
style={
27+
Object {
28+
"paddingBottom": "100%",
29+
}
30+
}
31+
>
32+
<div
33+
className="src-shared-components-ScalableRect-___style__wrapper___3qZoW"
34+
>
35+
CONTENT
36+
</div>
37+
</div>
38+
</div>
39+
`;

docs/jest-config.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ Standard configurations for [Jest](https://facebook.github.io/jest/).
44
**Why?** &mdash; We use Jest for unit-testing of critical code. Having
55
a standard configuration and setup reused between our projects, helps a lot.
66

7-
*TO BE WRITTEN*
7+
For Jest configuration this package provides:
8+
- **`config/jest/default`** &mdash; The standard Jest config;
9+
- **`config/jest/setup`** &mdash; The standard Jest setup script. At the moment
10+
it just sets up [`raf/polyfill`](https://www.npmjs.com/package/raf), required
11+
by React.

src/shared/components/GenericLink.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function GenericLink(props) {
5858
* preventing event processing by React Router. */
5959
const url = new Url(to);
6060
if (url.origin !== document.location.origin) {
61-
document.location = to;
61+
document.location.assign(to);
6262
e.preventDefault();
6363

6464
/* Scroll to the top-left corner of the page, just in case the link

0 commit comments

Comments
 (0)