Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pattern and path to regexp create errors #2477 #2485

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify tests
  • Loading branch information
jasoniangreen committed Aug 7, 2024
commit 1110b700147718bf2b51a9c9dba859eab166a107
26 changes: 4 additions & 22 deletions spec/issues/2477_informative_pattern_errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _Ajv from "../ajv2020"
import * as assert from "assert"

describe("Invalid regexp patterns should throw more informative errors (issue #2477)", () => {
describe.only("Invalid regexp patterns should throw more informative errors (issue #2477)", () => {
it("throws with pattern and schema path", () => {
const ajv = new _Ajv()

Expand All @@ -12,13 +12,7 @@ describe("Invalid regexp patterns should throw more informative errors (issue #2

assert.throws(
() => ajv.compile(rootSchema),
(thrown: unknown) => {
assert.equal(
(thrown as Error).message,
"Invalid regular expression: /^[0-9]{2-4}/: Incomplete quantifier | pattern ^[0-9]{2-4} at #"
)
return true
}
(thrown: Error) => thrown.message.includes("pattern ^[0-9]{2-4} at #")
)

const pathSchema = {
Expand All @@ -30,13 +24,7 @@ describe("Invalid regexp patterns should throw more informative errors (issue #2

assert.throws(
() => ajv.compile(pathSchema),
(thrown: unknown) => {
assert.equal(
(thrown as Error).message,
"Invalid regular expression: /^[0-9]{2-4}/: Incomplete quantifier | pattern ^[0-9]{2-4} at #/properties/foo"
)
return true
}
(thrown: Error) => thrown.message.includes("pattern ^[0-9]{2-4} at #/properties/foo")
)
})
it("throws with pattern and schema path with $data", () => {
Expand All @@ -52,13 +40,7 @@ describe("Invalid regexp patterns should throw more informative errors (issue #2

assert.throws(
() => ajv.compile(validate({shouldMatch: "^[0-9]{2-4}", string: "123"})),
(thrown: unknown) => {
assert.equal(
(thrown as Error).message,
"Invalid regular expression: /^[0-9]{2-4}/: Incomplete quantifier | pattern ^[0-9]{2-4} at #/properties/string"
)
return true
}
(thrown: Error) => thrown.message.includes("pattern ^[0-9]{2-4} at #/properties/string")
)
})
})