Skip to content

Commit 1c193b1

Browse files
committed
Tests
1 parent 1081e3a commit 1c193b1

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'; // eslint-disable-line no-unused-vars
2+
import { expect } from 'chai';
3+
import { shallow } from 'enzyme';
4+
import NetworkStatus from '../../components/network-status';
5+
6+
function setup() {
7+
const props = {};
8+
const wrapper = shallow(<NetworkStatus {...props} />);
9+
10+
return {
11+
props: props,
12+
wrapper: wrapper,
13+
};
14+
};
15+
16+
describe('components/network-status.js', function () {
17+
18+
it('should render itself & its children', function () {
19+
20+
const { wrapper } = setup();
21+
22+
expect(wrapper).to.exist;
23+
expect(wrapper.find('.alert').text()).to.equal('Couldn\'t establish an internet connection.');
24+
25+
});
26+
27+
});

src/js/__tests__/containers/app.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'; // eslint-disable-line no-unused-vars
22
import { expect } from 'chai';
3-
import { shallow } from 'enzyme';
4-
import App from '../../containers/app';
3+
import { shallow, mount } from 'enzyme';
4+
import { App } from '../../containers/app';
55

6-
function setup() {
6+
function setupShallow() {
77
const props = {
88
location: '/home'
99
};
@@ -15,11 +15,24 @@ function setup() {
1515
};
1616
};
1717

18+
function setupMount() {
19+
const props = {
20+
location: '/home'
21+
};
22+
const wrapper = mount(<App {...props} />);
23+
24+
return {
25+
props: props,
26+
wrapper: wrapper,
27+
};
28+
};
29+
30+
1831
describe('containers/app.js', function () {
1932

2033
it('should render itself & its children', function () {
2134

22-
const { wrapper } = setup();
35+
const { wrapper } = setupShallow();
2336

2437
expect(wrapper).to.exist;
2538
expect(wrapper.state().showSearch).to.be.false;
@@ -28,4 +41,14 @@ describe('containers/app.js', function () {
2841
expect(wrapper.state().showSearch).to.be.true;
2942
});
3043

44+
it('should mount itself & its children', function () {
45+
46+
const { wrapper } = setupMount();
47+
48+
expect(wrapper).to.exist;
49+
50+
wrapper.instance().handleNetworkStatus();
51+
expect(wrapper.state().networkConnected).to.be.false;
52+
});
53+
3154
});

0 commit comments

Comments
 (0)