Skip to content

Commit 388a5b6

Browse files
committed
skip jest-fetch-mock
1 parent ae7e371 commit 388a5b6

File tree

3 files changed

+319
-34
lines changed

3 files changed

+319
-34
lines changed

__tests__/__snapshots__/index.test.js.snap

Lines changed: 308 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,316 @@ Array [
66
"Content-Type",
77
"application/json; charset=utf-8",
88
],
9+
Array [
10+
"Content-Length",
11+
"5100",
12+
],
913
]
1014
`;
1115

1216
exports[`expect res setHeader and end to match snapshot 2`] = `
13-
Array [
14-
Array [
15-
"{\\"data\\":{\\"registry\\":{\\"href\\":\\"http://mock:3000/\\",\\"ocVersion\\":\\"1.2.3\\",\\"type\\":\\"mock-registry\\",\\"dependencies\\":[\\"graphql\\",\\"lodash\\",\\"moment\\"]},\\"components\\":[{\\"name\\":\\"oc-a-component\\",\\"description\\":\\"Awesome OpenComponent\\",\\"version\\":\\"4.5.6\\",\\"allVersions\\":[\\"4.5.4\\",\\"4.5.5\\",\\"4.5.6\\"],\\"author\\":null,\\"repository\\":null,\\"parameters\\":[{\\"key\\":\\"id\\",\\"type\\":\\"string\\",\\"mandatory\\":true,\\"example\\":\\"815\\",\\"description\\":\\"The Id\\"}]}],\\"component\\":{\\"name\\":\\"oc-a-component\\",\\"description\\":\\"Awesome OpenComponent\\",\\"version\\":\\"4.5.6\\",\\"allVersions\\":[\\"4.5.4\\",\\"4.5.5\\",\\"4.5.6\\"],\\"author\\":null,\\"repository\\":null,\\"parameters\\":[{\\"key\\":\\"id\\",\\"type\\":\\"string\\",\\"mandatory\\":true,\\"example\\":\\"815\\",\\"description\\":\\"The Id\\"}]}}}",
16-
],
17-
]
17+
Object {
18+
"data": Object {
19+
"component": Object {
20+
"allVersions": Array [
21+
"1.3.0",
22+
"1.2.0",
23+
"1.1.1",
24+
"1.1.0",
25+
"1.0.0",
26+
],
27+
"author": Object {
28+
"email": "[email protected]",
29+
"name": "Mattia Richetto",
30+
},
31+
"description": "This component displays picture, title, description and date of the NASA's Astronomy Picture of the Day",
32+
"name": "oc-apod",
33+
"parameters": Array [
34+
Object {
35+
"description": "The NASA Open APIs key",
36+
"example": "DEMO_KEY",
37+
"key": "apiKey",
38+
"mandatory": true,
39+
"type": "string",
40+
},
41+
],
42+
"repository": Object {
43+
"type": "git",
44+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-apod",
45+
},
46+
"version": "1.3.0",
47+
},
48+
"components": Array [
49+
Object {
50+
"allVersions": Array [
51+
"1.3.0",
52+
"1.2.0",
53+
"1.1.1",
54+
"1.1.0",
55+
"1.0.0",
56+
],
57+
"author": Object {
58+
"email": "[email protected]",
59+
"name": "Mattia Richetto",
60+
},
61+
"description": "This component displays picture, title, description and date of the NASA's Astronomy Picture of the Day",
62+
"name": "oc-apod",
63+
"parameters": Array [
64+
Object {
65+
"description": "The NASA Open APIs key",
66+
"example": "DEMO_KEY",
67+
"key": "apiKey",
68+
"mandatory": true,
69+
"type": "string",
70+
},
71+
],
72+
"repository": Object {
73+
"type": "git",
74+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-apod",
75+
},
76+
"version": "1.3.0",
77+
},
78+
Object {
79+
"allVersions": Array [
80+
"0.37.4",
81+
"0.37.2",
82+
"0.37.0",
83+
"0.36.27",
84+
"0.36.26",
85+
"0.36.25",
86+
"0.36.21",
87+
"0.36.13",
88+
"0.36.4",
89+
"0.36.1",
90+
],
91+
"author": Object {
92+
"email": null,
93+
"name": null,
94+
},
95+
"description": "The OpenComponents client-side javascript client",
96+
"name": "oc-client",
97+
"parameters": Array [],
98+
"repository": Object {
99+
"type": null,
100+
"url": null,
101+
},
102+
"version": "0.37.4",
103+
},
104+
Object {
105+
"allVersions": Array [
106+
"1.1.0",
107+
"1.0.1",
108+
"1.0.0",
109+
],
110+
"author": Object {
111+
"email": "[email protected]",
112+
"name": "Mattia Richetto",
113+
},
114+
"description": "A header for a website with logo and title",
115+
"name": "oc-columbus-header",
116+
"parameters": Array [
117+
Object {
118+
"description": "The main title",
119+
"example": "Instagram",
120+
"key": "title",
121+
"mandatory": true,
122+
"type": "string",
123+
},
124+
Object {
125+
"description": "The logo's absolute url",
126+
"example": "http://www.uidownload.com/files/722/15/621/facebook-instagram-instagram-2016-instagram-logo-new-new-instagram-icon.png",
127+
"key": "logoUrl",
128+
"mandatory": true,
129+
"type": "string",
130+
},
131+
],
132+
"repository": Object {
133+
"type": "git",
134+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-columbus-header",
135+
},
136+
"version": "1.1.0",
137+
},
138+
Object {
139+
"allVersions": Array [
140+
"1.0.4",
141+
"1.0.3",
142+
"1.0.2",
143+
"1.0.1",
144+
"1.0.0",
145+
],
146+
"author": Object {
147+
"email": "[email protected]",
148+
"name": "Mattia Richetto",
149+
},
150+
"description": "This example shows how to make an HTTP POST request w/ OpenComponents.",
151+
"name": "oc-feedback-form",
152+
"parameters": Array [],
153+
"repository": Object {
154+
"type": "git",
155+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-feedback-form",
156+
},
157+
"version": "1.0.4",
158+
},
159+
Object {
160+
"allVersions": Array [
161+
"1.0.0-alpha.2",
162+
"1.0.0-alpha.1",
163+
],
164+
"author": Object {
165+
"email": "[email protected]",
166+
"name": "Mattia Richetto",
167+
},
168+
"description": "oc-micro-api",
169+
"name": "oc-micro-api",
170+
"parameters": Array [],
171+
"repository": Object {
172+
"type": "git",
173+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-micro-api",
174+
},
175+
"version": "1.0.0-alpha.2",
176+
},
177+
Object {
178+
"allVersions": Array [
179+
"1.7.0",
180+
"1.6.1",
181+
"1.6.0",
182+
"1.5.0",
183+
"1.4.0",
184+
"1.3.0",
185+
"1.2.0",
186+
"1.1.0",
187+
"1.0.0",
188+
],
189+
"author": Object {
190+
"email": "[email protected]",
191+
"name": "Mattia Richetto",
192+
},
193+
"description": "When, from where and what is going to be my next run.",
194+
"name": "oc-my-next-run",
195+
"parameters": Array [
196+
Object {
197+
"description": "The id of the run to display",
198+
"example": "2017-03-19",
199+
"key": "id",
200+
"mandatory": true,
201+
"type": "string",
202+
},
203+
],
204+
"repository": Object {
205+
"type": "git",
206+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-my-next-run",
207+
},
208+
"version": "1.7.0",
209+
},
210+
Object {
211+
"allVersions": Array [
212+
"1.1.1",
213+
"1.1.0",
214+
"1.0.0",
215+
],
216+
"author": Object {
217+
"email": "[email protected]",
218+
"name": "Mattia Richetto",
219+
},
220+
"description": "The list of my social media; this component is used in https://mattiaerre.github.io's footer",
221+
"name": "oc-social-media-buttons",
222+
"parameters": Array [],
223+
"repository": Object {
224+
"type": "git",
225+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-social-media-buttons",
226+
},
227+
"version": "1.1.1",
228+
},
229+
Object {
230+
"allVersions": Array [
231+
"1.0.0",
232+
],
233+
"author": Object {
234+
"email": "[email protected]",
235+
"name": "Mattia Richetto",
236+
},
237+
"description": "This is sometimes called timeago or relative time.",
238+
"name": "oc-timeago",
239+
"parameters": Array [
240+
Object {
241+
"description": "The start date as string in a YYYY-MM-DD format",
242+
"example": "2016-02-22",
243+
"key": "start",
244+
"mandatory": true,
245+
"type": "string",
246+
},
247+
Object {
248+
"description": "The end date as string in a YYYY-MM-DD format",
249+
"example": "2017-02-22",
250+
"key": "end",
251+
"mandatory": false,
252+
"type": "string",
253+
},
254+
],
255+
"repository": Object {
256+
"type": "git",
257+
"url": "https://github.com/mattiaerre/oc-hub/tree/master/oc-timeago",
258+
},
259+
"version": "1.0.0",
260+
},
261+
Object {
262+
"allVersions": Array [
263+
"1.0.1",
264+
"1.0.0",
265+
"1.0.0-alpha.1",
266+
],
267+
"author": Object {
268+
"email": "[email protected]",
269+
"name": "Mattia Richetto",
270+
},
271+
"description": "This is the Google Universal Analytics tracking code for a given Tracking ID.",
272+
"name": "oc-ua-tracking-code",
273+
"parameters": Array [
274+
Object {
275+
"description": "The Google Analytics Tracking ID",
276+
"example": "UA-12345678-9",
277+
"key": "trackingId",
278+
"mandatory": true,
279+
"type": "string",
280+
},
281+
],
282+
"repository": Object {
283+
"type": "git",
284+
"url": "https://github.com/mattiaerre/oc-ua-tracking-code/tree/master/oc-micro-api",
285+
},
286+
"version": "1.0.1",
287+
},
288+
Object {
289+
"allVersions": Array [
290+
"1.1.1",
291+
"1.1.0",
292+
"1.0.1",
293+
"1.0.0",
294+
],
295+
"author": Object {
296+
"email": "[email protected]",
297+
"name": "Mattia Richetto",
298+
},
299+
"description": "oc-with-react",
300+
"name": "oc-with-react",
301+
"parameters": Array [],
302+
"repository": Object {
303+
"type": null,
304+
"url": null,
305+
},
306+
"version": "1.1.1",
307+
},
308+
],
309+
"registry": Object {
310+
"dependencies": Array [
311+
"graphql",
312+
"lodash",
313+
"moment",
314+
],
315+
"href": "https://pink-pineapple.herokuapp.com/",
316+
"ocVersion": "0.37.4",
317+
"type": "oc-registry",
318+
},
319+
},
320+
}
18321
`;

__tests__/index.test.js

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const fetch = require('node-fetch');
1+
// const fetch = require('node-fetch');
22
const factory = require('../src');
33

44
const options = {
5-
baseUrl: 'http://mock:3000/',
5+
baseUrl: 'https://pink-pineapple.herokuapp.com/',
66
graphiql: true,
77
dependencies: ['graphql', 'lodash', 'moment']
88
};
@@ -66,41 +66,21 @@ test('expect type of middleware to be function', () => {
6666
expect(typeof middleware).toBe('function');
6767
});
6868

69-
test.skip('expect res setHeader and end to match snapshot', async () => {
70-
// todo: change mockResponse
71-
fetch.mockResponse(JSON.stringify({
72-
href: options.baseUrl,
73-
ocVersion: '1.2.3',
74-
type: 'mock-registry',
75-
components: [
76-
`${options.baseUrl}oc-a-component`
77-
],
78-
name: 'oc-a-component',
79-
description: 'Awesome OpenComponent',
80-
version: '4.5.6',
81-
allVersions: ['4.5.4', '4.5.5', '4.5.6'],
82-
oc: {
83-
parameters: {
84-
id: {
85-
type: 'string',
86-
mandatory: true,
87-
example: '815',
88-
description: 'The Id'
89-
}
90-
}
91-
}
92-
}));
93-
69+
test('expect res setHeader and end to match snapshot', async () => {
9470
const req = {
9571
method: 'GET',
96-
headers: {},
72+
headers: {
73+
'Content-Type': 'application/json'
74+
},
9775
url: `?query=${query}`
9876
};
9977

10078
const res = { setHeader: jest.fn(), end: jest.fn() };
10179

10280
await middleware(req, res);
10381

82+
expect(res.setHeader).toHaveBeenCalled();
10483
expect(res.setHeader.mock.calls).toMatchSnapshot();
105-
expect(res.end.mock.calls).toMatchSnapshot();
84+
expect(res.end).toHaveBeenCalled();
85+
expect(JSON.parse(res.end.mock.calls)).toMatchSnapshot();
10686
});

setupJest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/*
12
require('isomorphic-fetch');
23
const fetch = require('jest-fetch-mock');
34
45
jest.setMock('node-fetch', fetch);
6+
*/

0 commit comments

Comments
 (0)