1
1
import { http , HttpResponse } from "msw" ;
2
+ import { assert , expect , test } from "vitest" ;
2
3
import { server } from "../../vitest.setup.js" ;
3
4
import fetchJsonLd from "./fetchJsonLd.js" ;
4
- import { assert , expect , test } from "vitest" ;
5
5
6
6
const httpResponse = {
7
7
"@context" : "http://json-ld.org/contexts/person.jsonld" ,
@@ -33,13 +33,15 @@ test("fetch a JSON-LD document", async () => {
33
33
34
34
test ( "fetch a non JSON-LD document" , async ( ) => {
35
35
server . use (
36
- http . get ( "http://localhost/foo.jsonld" , ( ) => {
37
- return new HttpResponse ( `<body>Hello</body>` , {
38
- headers : { "Content-Type" : "text/html" } ,
39
- status : 200 ,
40
- statusText : "OK" ,
41
- } ) ;
42
- } ) ,
36
+ http . get (
37
+ "http://localhost/foo.jsonld" ,
38
+ ( ) =>
39
+ new HttpResponse ( `<body>Hello</body>` , {
40
+ headers : { "Content-Type" : "text/html" } ,
41
+ status : 200 ,
42
+ statusText : "OK" ,
43
+ } ) ,
44
+ ) ,
43
45
) ;
44
46
45
47
const promise = fetchJsonLd ( "http://localhost/foo.jsonld" ) ;
@@ -50,13 +52,13 @@ test("fetch a non JSON-LD document", async () => {
50
52
51
53
test ( "fetch an error with Content-Type application/ld+json" , async ( ) => {
52
54
server . use (
53
- http . get ( "http://localhost/foo.jsonld" , ( ) => {
54
- return HttpResponse . json ( httpResponse , {
55
+ http . get ( "http://localhost/foo.jsonld" , ( ) =>
56
+ HttpResponse . json ( httpResponse , {
55
57
status : 500 ,
56
58
statusText : "Internal Server Error" ,
57
59
headers : { "Content-Type" : "application/ld+json" } ,
58
- } ) ;
59
- } ) ,
60
+ } ) ,
61
+ ) ,
60
62
) ;
61
63
62
64
const rejectedResponse = await fetchJsonLd (
@@ -72,13 +74,13 @@ test("fetch an error with Content-Type application/ld+json", async () => {
72
74
73
75
test ( "fetch an error with Content-Type application/error+json" , async ( ) => {
74
76
server . use (
75
- http . get ( "http://localhost/foo.jsonld" , ( ) => {
76
- return HttpResponse . json ( httpResponse , {
77
+ http . get ( "http://localhost/foo.jsonld" , ( ) =>
78
+ HttpResponse . json ( httpResponse , {
77
79
status : 400 ,
78
80
statusText : "Bad Request" ,
79
81
headers : { "Content-Type" : "application/error+json" } ,
80
- } ) ;
81
- } ) ,
82
+ } ) ,
83
+ ) ,
82
84
) ;
83
85
84
86
const rejectedResponse = await fetchJsonLd (
@@ -94,13 +96,15 @@ test("fetch an error with Content-Type application/error+json", async () => {
94
96
95
97
test ( "fetch an empty document" , async ( ) => {
96
98
server . use (
97
- http . get ( "http://localhost/foo.jsonld" , ( ) => {
98
- return new HttpResponse ( `` , {
99
- status : 204 ,
100
- statusText : "No Content" ,
101
- headers : { "Content-Type" : "text/html" } ,
102
- } ) ;
103
- } ) ,
99
+ http . get (
100
+ "http://localhost/foo.jsonld" ,
101
+ ( ) =>
102
+ new HttpResponse ( `` , {
103
+ status : 204 ,
104
+ statusText : "No Content" ,
105
+ headers : { "Content-Type" : "text/html" } ,
106
+ } ) ,
107
+ ) ,
104
108
) ;
105
109
106
110
const dataPromise = fetchJsonLd ( "http://localhost/foo.jsonld" ) ;
0 commit comments