Skip to content

Commit fbccfcd

Browse files
committed
update test cases to unregister schema after completing the test.
1 parent 30b467b commit fbccfcd

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/normalizeOutputFormat/normalizeOutput.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { registerSchema, unregisterSchema } from "@hyperjump/json-schema/draft-2
88

99
describe.only("Error Output Normalization", () => {
1010
test("Simple keyword with a standard Basic output format", async () => {
11+
const schemaUri = "https://example.com/main";
1112
registerSchema({
12-
$id: "https://example.com/main1",
1313
$schema: "https://json-schema.org/draft/2020-12/schema",
1414
minLength: 3
15-
});
15+
}, schemaUri);
1616

1717
const instance = "aa";
1818

@@ -21,28 +21,29 @@ describe.only("Error Output Normalization", () => {
2121
valid: false,
2222
errors: [
2323
{
24-
absoluteKeywordLocation: "https://example.com/main1#/minLength",
24+
absoluteKeywordLocation: "https://example.com/main#/minLength",
2525
instanceLocation: "#"
2626
}
2727
]
2828
};
2929

3030
const result = await betterJsonSchemaErrors(instance, output);
3131
expect(result.errors).to.eql([{
32-
schemaLocation: "https://example.com/main1#/minLength",
32+
schemaLocation: "https://example.com/main#/minLength",
3333
instanceLocation: "#",
3434
message: "The instance should be at least 3 characters"
3535
}
3636
]);
37+
unregisterSchema(schemaUri);
3738
});
3839

3940
test("Checking when output contain only instanceLocation and keywordLocation ", async () => {
41+
const schemaUri = "https://example.com/main";
4042
registerSchema({
41-
$id: "https://example.com/main2",
4243
$schema: "https://json-schema.org/draft/2020-12/schema",
4344
minLength: 3
44-
});
45-
const schemaUri = "https://example.com/main2";
45+
}, schemaUri);
46+
4647
const instance = "aa";
4748

4849
/** @type OutputFormat */
@@ -58,18 +59,19 @@ describe.only("Error Output Normalization", () => {
5859

5960
const result = await betterJsonSchemaErrors(instance, output, { schemaUri });
6061
expect(result.errors).to.eql([{
61-
schemaLocation: "https://example.com/main2#/minLength",
62+
schemaLocation: "https://example.com/main#/minLength",
6263
instanceLocation: "#",
6364
message: "The instance should be at least 3 characters"
6465
}]);
66+
unregisterSchema(schemaUri);
6567
});
6668

6769
test("adding # if instanceLocation doesn't have it", async () => {
70+
const schemaUri = "https://example.com/main";
6871
registerSchema({
69-
$id: "https://example.com/main3",
7072
$schema: "https://json-schema.org/draft/2020-12/schema",
7173
minLength: 3
72-
});
74+
}, schemaUri);
7375

7476
const instance = "aa";
7577

@@ -79,18 +81,19 @@ describe.only("Error Output Normalization", () => {
7981
errors: [
8082
{
8183
valid: false,
82-
absoluteKeywordLocation: "https://example.com/main3#/minLength",
84+
absoluteKeywordLocation: "https://example.com/main#/minLength",
8385
instanceLocation: ""
8486
}
8587
]
8688
};
8789

8890
const result = await betterJsonSchemaErrors(instance, output);
8991
expect(result.errors).to.eql([{
90-
schemaLocation: "https://example.com/main3#/minLength",
92+
schemaLocation: "https://example.com/main#/minLength",
9193
instanceLocation: "#",
9294
message: "The instance should be at least 3 characters"
9395
}]);
96+
unregisterSchema(schemaUri);
9497
});
9598

9699
test("checking for the basic output format", async () => {
@@ -246,8 +249,8 @@ describe.only("Error Output Normalization", () => {
246249
});
247250

248251
test("correctly resolves keywordLocation through $ref in $defs", async () => {
252+
const schemaUri = "https://example.com/main";
249253
registerSchema({
250-
$id: "https://example.com/main5",
251254
$schema: "https://json-schema.org/draft/2020-12/schema",
252255
properties: {
253256
foo: { $ref: "#/$defs/lengthDefinition" }
@@ -257,7 +260,7 @@ describe.only("Error Output Normalization", () => {
257260
minLength: 3
258261
}
259262
}
260-
});
263+
}, schemaUri);
261264
const instance = { foo: "aa" };
262265
/** @type OutputFormat */
263266
const output = {
@@ -269,11 +272,10 @@ describe.only("Error Output Normalization", () => {
269272
}
270273
]
271274
};
272-
const schemaUri = "https://example.com/main5";
273275
const result = await betterJsonSchemaErrors(instance, output, { schemaUri });
274276
expect(result.errors).to.eql([
275277
{
276-
schemaLocation: "https://example.com/main5#/$defs/lengthDefinition/minLength",
278+
schemaLocation: "https://example.com/main#/$defs/lengthDefinition/minLength",
277279
instanceLocation: "#",
278280
message: "The instance should be at least 3 characters"
279281
}

0 commit comments

Comments
 (0)