forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline-view-test.js
46 lines (37 loc) · 1.3 KB
/
offline-view-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react';
import {shallow} from 'enzyme';
import OfflineView from '../../lib/views/offline-view';
describe('OfflineView', function() {
let listeners;
beforeEach(function() {
listeners = {};
sinon.stub(window, 'addEventListener').callsFake((eventName, callback) => {
listeners[eventName] = callback;
});
sinon.stub(window, 'removeEventListener').callsFake((eventName, callback) => {
if (listeners[eventName] === callback) {
delete listeners[eventName];
} else {
throw new Error('Wrong callback');
}
});
});
it('triggers a retry callback when the retry button is clicked', function() {
const retry = sinon.spy();
const wrapper = shallow(<OfflineView retry={retry} />);
wrapper.find('.btn').simulate('click');
assert.isTrue(retry.called);
});
it('triggers a retry callback when the network status changes', function() {
const retry = sinon.spy();
shallow(<OfflineView retry={retry} />);
listeners.online();
assert.strictEqual(retry.callCount, 1);
});
it('unregisters the network status listener on unmount', function() {
const wrapper = shallow(<OfflineView retry={() => {}} />);
assert.isDefined(listeners.online);
wrapper.unmount();
assert.isUndefined(listeners.online);
});
});