This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathquery-error-tile.test.js
More file actions
72 lines (57 loc) · 2.39 KB
/
query-error-tile.test.js
File metadata and controls
72 lines (57 loc) · 2.39 KB
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
import React from 'react';
import {shallow} from 'enzyme';
import QueryErrorTile from '../../lib/views/query-error-tile';
describe('QueryErrorTile', function() {
beforeEach(function() {
sinon.stub(console, 'error');
});
it('logs the full error information to the console', function() {
const e = new Error('wat');
e.rawStack = e.stack;
shallow(<QueryErrorTile error={e} />);
// eslint-disable-next-line no-console
assert.isTrue(console.error.calledWith(sinon.match.string, e));
});
it('displays each GraphQL error', function() {
const e = new Error('wat');
e.rawStack = e.stack;
e.errors = [
{message: 'okay first of all'},
{message: 'and another thing'},
];
const wrapper = shallow(<QueryErrorTile error={e} />);
const messages = wrapper.find('.github-QueryErrorTile-message');
assert.lengthOf(messages, 2);
assert.strictEqual(messages.at(0).find('Octicon').prop('icon'), 'alert');
assert.match(messages.at(0).text(), /okay first of all/);
assert.strictEqual(messages.at(1).find('Octicon').prop('icon'), 'alert');
assert.match(messages.at(1).text(), /and another thing/);
});
it('displays the text of a failed HTTP response', function() {
const e = new Error('500');
e.rawStack = e.stack;
e.response = {};
e.responseText = 'The server is on fire';
const wrapper = shallow(<QueryErrorTile error={e} />);
const message = wrapper.find('.github-QueryErrorTile-message');
assert.strictEqual(message.find('Octicon').prop('icon'), 'alert');
assert.match(message.text(), /The server is on fire$/);
});
it('displays an offline message', function() {
const e = new Error('cat pulled out the ethernet cable');
e.rawStack = e.stack;
e.network = true;
const wrapper = shallow(<QueryErrorTile error={e} />);
const message = wrapper.find('.github-QueryErrorTile-message');
assert.strictEqual(message.find('Octicon').prop('icon'), 'alignment-unalign');
assert.match(message.text(), /Offline/);
});
it('falls back to displaying the raw error message', function() {
const e = new TypeError('oh no');
e.rawStack = e.stack;
const wrapper = shallow(<QueryErrorTile error={e} />);
const message = wrapper.find('.github-QueryErrorTile-message');
assert.strictEqual(message.find('Octicon').prop('icon'), 'alert');
assert.match(message.text(), /TypeError: oh no/);
});
});