@@ -1149,7 +1149,7 @@ test("parse a Hydra documentation without authorization", () => {
1149
1149
} ) ;
1150
1150
} ) ;
1151
1151
1152
- test ( 'Parse entrypoint without "@type" key' , ( ) => {
1152
+ test ( 'Parse entrypoint without "@type" key' , async ( ) => {
1153
1153
const entrypoint = `{
1154
1154
"@context": {
1155
1155
"@vocab": "http://localhost/docs.jsonld#",
@@ -1175,12 +1175,18 @@ test('Parse entrypoint without "@type" key', () => {
1175
1175
1176
1176
fetch . mockResponses ( [ entrypoint , init ] , [ docs , init ] ) ;
1177
1177
1178
- parseHydraDocumentation ( "http://localhost/" ) . catch ( data => {
1179
- expect ( data . message ) . toBe ( 'The API entrypoint has no "@type" key.' ) ;
1180
- } ) ;
1178
+ const expectedError = { message : "" } ;
1179
+
1180
+ try {
1181
+ await parseHydraDocumentation ( "http://localhost/" ) ;
1182
+ } catch ( error ) {
1183
+ expectedError . message = error . message ;
1184
+ }
1185
+
1186
+ expect ( expectedError . message ) . toBe ( 'The API entrypoint has no "@type" key.' ) ;
1181
1187
} ) ;
1182
1188
1183
- test ( 'Parse entrypoint class without "supportedClass" key' , ( ) => {
1189
+ test ( 'Parse entrypoint class without "supportedClass" key' , async ( ) => {
1184
1190
const docs = `{
1185
1191
"@context": {
1186
1192
"@vocab": "http://localhost/docs.jsonld#",
@@ -1218,14 +1224,20 @@ test('Parse entrypoint class without "supportedClass" key', () => {
1218
1224
1219
1225
fetch . mockResponses ( [ entrypoint , init ] , [ docs , init ] ) ;
1220
1226
1221
- parseHydraDocumentation ( "http://localhost/" ) . catch ( data => {
1222
- expect ( data . message ) . toBe (
1223
- 'The API documentation has no "http://www.w3.org/ns/hydra/core#supportedClass" key or its value is not an array.'
1224
- ) ;
1225
- } ) ;
1227
+ const expectedError = { message : "" } ;
1228
+
1229
+ try {
1230
+ await parseHydraDocumentation ( "http://localhost/" ) ;
1231
+ } catch ( error ) {
1232
+ expectedError . message = error . message ;
1233
+ }
1234
+
1235
+ expect ( expectedError . message ) . toBe (
1236
+ 'The API documentation has no "http://www.w3.org/ns/hydra/core#supportedClass" key or its value is not an array.'
1237
+ ) ;
1226
1238
} ) ;
1227
1239
1228
- test ( 'Parse entrypoint class without "supportedProperty" key' , ( ) => {
1240
+ test ( 'Parse entrypoint class without "supportedProperty" key' , async ( ) => {
1229
1241
const docs = `{
1230
1242
"@context": {
1231
1243
"@vocab": "http://localhost/docs.jsonld#",
@@ -1276,33 +1288,51 @@ test('Parse entrypoint class without "supportedProperty" key', () => {
1276
1288
1277
1289
fetch . mockResponses ( [ entrypoint , init ] , [ docs , init ] ) ;
1278
1290
1279
- parseHydraDocumentation ( "http://localhost/" ) . catch ( data => {
1280
- expect ( data . message ) . toBe (
1281
- 'The entrypoint definition has no "http://www.w3.org/ns/hydra/core#supportedProperty" key or it is not an array.'
1282
- ) ;
1283
- } ) ;
1291
+ const expectedError = { message : "" } ;
1292
+
1293
+ try {
1294
+ await parseHydraDocumentation ( "http://localhost/" ) ;
1295
+ } catch ( error ) {
1296
+ expectedError . message = error . message ;
1297
+ }
1298
+
1299
+ expect ( expectedError . message ) . toBe (
1300
+ 'The entrypoint definition has no "http://www.w3.org/ns/hydra/core#supportedProperty" key or it is not an array.'
1301
+ ) ;
1284
1302
} ) ;
1285
1303
1286
- test ( "Invalid docs JSON" , ( ) => {
1304
+ test ( "Invalid docs JSON" , async ( ) => {
1287
1305
const docs = `{foo,}` ;
1288
1306
1289
1307
fetch . mockResponses ( [ entrypoint , init ] , [ docs , init ] ) ;
1290
1308
1291
- parseHydraDocumentation ( "http://localhost/" ) . catch ( data => {
1292
- expect ( data ) . toHaveProperty ( "api" ) ;
1293
- expect ( data ) . toHaveProperty ( "response" ) ;
1294
- expect ( data ) . toHaveProperty ( "status" ) ;
1295
- } ) ;
1309
+ let expectedError = { } ;
1310
+
1311
+ try {
1312
+ await parseHydraDocumentation ( "http://localhost/" ) ;
1313
+ } catch ( error ) {
1314
+ expectedError = error ;
1315
+ }
1316
+
1317
+ expect ( expectedError ) . toHaveProperty ( "api" ) ;
1318
+ expect ( expectedError ) . toHaveProperty ( "response" ) ;
1319
+ expect ( expectedError ) . toHaveProperty ( "status" ) ;
1296
1320
} ) ;
1297
1321
1298
- test ( "Invalid entrypoint JSON" , ( ) => {
1322
+ test ( "Invalid entrypoint JSON" , async ( ) => {
1299
1323
const entrypoint = `{foo,}` ;
1300
1324
1301
1325
fetch . mockResponses ( [ entrypoint , init ] , [ docs , init ] ) ;
1302
1326
1303
- parseHydraDocumentation ( "http://localhost/" ) . catch ( data => {
1304
- expect ( data ) . toHaveProperty ( "api" ) ;
1305
- expect ( data ) . toHaveProperty ( "response" ) ;
1306
- expect ( data ) . toHaveProperty ( "status" ) ;
1307
- } ) ;
1327
+ let expectedError = { } ;
1328
+
1329
+ try {
1330
+ await parseHydraDocumentation ( "http://localhost/" ) ;
1331
+ } catch ( error ) {
1332
+ expectedError = error ;
1333
+ }
1334
+
1335
+ expect ( expectedError ) . toHaveProperty ( "api" ) ;
1336
+ expect ( expectedError ) . toHaveProperty ( "response" ) ;
1337
+ expect ( expectedError ) . toHaveProperty ( "status" ) ;
1308
1338
} ) ;
0 commit comments