Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoniangreen committed Aug 7, 2024
1 parent 4e3463d commit 1110b70
Showing 1 changed file with 4 additions and 22 deletions.
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")
)
})
})

0 comments on commit 1110b70

Please sign in to comment.