|
1 | | -import fetchJsonLd from './fetchJsonLd'; |
| 1 | +import fetchJsonLd from "./fetchJsonLd"; |
2 | 2 |
|
3 | | -test('fetch a JSON-LD document', () => { |
4 | | - fetch.mockResponseOnce(`{ |
| 3 | +test("fetch a JSON-LD document", () => { |
| 4 | + fetch.mockResponseOnce( |
| 5 | + `{ |
5 | 6 | "@context": "http://json-ld.org/contexts/person.jsonld", |
6 | 7 | "@id": "http://dbpedia.org/resource/John_Lennon", |
7 | 8 | "name": "John Lennon", |
8 | 9 | "born": "1940-10-09", |
9 | 10 | "spouse": "http://dbpedia.org/resource/Cynthia_Lennon" |
10 | | -}`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'application/ld+json'})}); |
11 | | - |
12 | | - return fetchJsonLd('/foo.jsonld').then(data => { |
13 | | - expect(data.response.ok).toBe(true); |
14 | | - expect(data.body.name).toBe('John Lennon'); |
| 11 | +}`, |
| 12 | + { |
| 13 | + status: 200, |
| 14 | + statusText: "OK", |
| 15 | + headers: new Headers({ "Content-Type": "application/ld+json" }) |
15 | 16 | } |
16 | 17 | ); |
| 18 | + |
| 19 | + return fetchJsonLd("/foo.jsonld").then(data => { |
| 20 | + expect(data.response.ok).toBe(true); |
| 21 | + expect(data.body.name).toBe("John Lennon"); |
| 22 | + }); |
17 | 23 | }); |
18 | 24 |
|
19 | | -test('fetch a non JSON-LD document', () => { |
20 | | - fetch.mockResponseOnce(`<body>Hello</body>`, {status: 200, statusText: 'OK', headers: new Headers({'Content-Type': 'text/html'})}); |
| 25 | +test("fetch a non JSON-LD document", () => { |
| 26 | + fetch.mockResponseOnce(`<body>Hello</body>`, { |
| 27 | + status: 200, |
| 28 | + statusText: "OK", |
| 29 | + headers: new Headers({ "Content-Type": "text/html" }) |
| 30 | + }); |
21 | 31 |
|
22 | | - return fetchJsonLd('/foo.jsonld').catch(data => { |
23 | | - expect(data.response.ok).toBe(true); |
24 | | - expect(typeof data.body).toBe('undefined'); |
25 | | - } |
26 | | - ); |
| 32 | + return fetchJsonLd("/foo.jsonld").catch(data => { |
| 33 | + expect(data.response.ok).toBe(true); |
| 34 | + expect(typeof data.body).toBe("undefined"); |
| 35 | + }); |
27 | 36 | }); |
28 | 37 |
|
29 | | -test('fetch an error', () => { |
30 | | - fetch.mockResponseOnce(`{ |
| 38 | +test("fetch an error", () => { |
| 39 | + fetch.mockResponseOnce( |
| 40 | + `{ |
31 | 41 | "@context": "http://json-ld.org/contexts/person.jsonld", |
32 | 42 | "@id": "http://dbpedia.org/resource/John_Lennon", |
33 | 43 | "name": "John Lennon", |
34 | 44 | "born": "1940-10-09", |
35 | 45 | "spouse": "http://dbpedia.org/resource/Cynthia_Lennon" |
36 | | -}`, {status: 400, statusText: 'Bad Request', headers: new Headers({'Content-Type': 'application/ld+json'})}); |
| 46 | +}`, |
| 47 | + { |
| 48 | + status: 400, |
| 49 | + statusText: "Bad Request", |
| 50 | + headers: new Headers({ "Content-Type": "application/ld+json" }) |
| 51 | + } |
| 52 | + ); |
37 | 53 |
|
38 | | - return fetchJsonLd('/foo.jsonld').catch(({response}) => { |
| 54 | + return fetchJsonLd("/foo.jsonld").catch(({ response }) => { |
39 | 55 | response.json().then(body => { |
40 | 56 | expect(response.ok).toBe(false); |
41 | | - expect(body.born).toBe('1940-10-09'); |
| 57 | + expect(body.born).toBe("1940-10-09"); |
42 | 58 | }); |
43 | 59 | }); |
44 | 60 | }); |
45 | 61 |
|
46 | | -test('fetch an empty document', () => { |
47 | | - fetch.mockResponseOnce('', {status: 204, statusText: 'No Content', headers: new Headers({'Content-Type': 'text/html'})}); |
| 62 | +test("fetch an empty document", () => { |
| 63 | + fetch.mockResponseOnce("", { |
| 64 | + status: 204, |
| 65 | + statusText: "No Content", |
| 66 | + headers: new Headers({ "Content-Type": "text/html" }) |
| 67 | + }); |
48 | 68 |
|
49 | | - return fetchJsonLd('/foo.jsonld').then(data => { |
| 69 | + return fetchJsonLd("/foo.jsonld").then(data => { |
50 | 70 | expect(data.response.ok).toBe(true); |
51 | 71 | expect(data.body).toBe(undefined); |
52 | 72 | }); |
|
0 commit comments