forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-error-view.test.js
82 lines (69 loc) · 2.49 KB
/
query-error-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import {shallow} from 'enzyme';
import QueryErrorView from '../../lib/views/query-error-view';
describe('QueryErrorView', function() {
function buildApp(overrideProps = {}) {
return (
<QueryErrorView
error={new Error('wat')}
login={() => {}}
openDevTools={() => {}}
{...overrideProps}
/>
);
}
it('renders a GithubLoginView for a 401', function() {
const error = new Error('Unauthorized');
error.response = {status: 401, text: () => ''};
error.rawStack = error.stack;
const login = sinon.stub();
const wrapper = shallow(buildApp({error, login}));
assert.isTrue(wrapper.find('GithubLoginView').exists());
assert.strictEqual(wrapper.find('GithubLoginView').prop('onLogin'), login);
});
it('renders GraphQL error messages', function() {
const error = new Error('GraphQL error');
error.response = {status: 200, text: () => ''};
error.errors = [
{message: 'first error'},
{message: 'second error'},
];
error.rawStack = error.stack;
const wrapper = shallow(buildApp({error}));
assert.isTrue(wrapper.find('ErrorView').someWhere(n => {
const ds = n.prop('descriptions');
return ds.includes('first error') && ds.includes('second error');
}));
});
it('recognizes network errors', function() {
const error = new Error('network error');
error.network = true;
error.rawStack = error.stack;
const retry = sinon.spy();
const wrapper = shallow(buildApp({error, retry}));
const ev = wrapper.find('OfflineView');
ev.prop('retry')();
assert.isTrue(retry.called);
});
it('renders the error response directly for an unrecognized error status', function() {
const error = new Error('GraphQL error');
error.response = {
status: 500,
};
error.responseText = 'response text';
error.rawStack = error.stack;
const wrapper = shallow(buildApp({error}));
assert.isTrue(wrapper.find('ErrorView').someWhere(n => {
return n.prop('descriptions').includes('response text') && n.prop('preformatted');
}));
});
it('falls back to rendering the message and stack', function() {
const error = new Error('the message');
error.rawStack = error.stack;
const wrapper = shallow(buildApp({error}));
const ev = wrapper.find('ErrorView');
assert.strictEqual(ev.prop('title'), 'the message');
assert.deepEqual(ev.prop('descriptions'), [error.stack]);
assert.isTrue(ev.prop('preformatted'));
});
});