Skip to content

Commit b2a671a

Browse files
committed
fix: issue #88
1 parent 469eb4b commit b2a671a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/keywords/enum.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { strict as assert } from "assert";
2+
3+
import { compileSchema } from "../compileSchema";
4+
5+
describe("keyword : enum : validate", () => {
6+
it("should return error of type enum-error", () => {
7+
const node = compileSchema({
8+
type: "string",
9+
enum: ["a", "b"]
10+
});
11+
12+
const { errors } = node.validate("c");
13+
14+
assert.deepEqual(errors.length, 1, "should have returned a single error");
15+
const [err] = errors;
16+
assert.deepEqual(err.code, "enum-error");
17+
assert(err.message.includes(JSON.stringify(["a", "b"])), "error message should mentioned valid values");
18+
});
19+
});

src/keywords/enum.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function validateEnum({ node, data, pointer = "#" }: JsonSchemaValidatorParams)
2424
return node.createError("enum-error", {
2525
pointer,
2626
schema,
27-
value: data
27+
value: data,
28+
values: schema.enum
2829
});
2930
}

0 commit comments

Comments
 (0)