Skip to content

Commit dcad387

Browse files
committed
Add unit test for validation utils
1 parent b57e787 commit dcad387

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { WidgetValidationError, throwOnIllegalChars, throwOnNoMatch } from "../validation"
2+
3+
describe("Validation Utilities", () => {
4+
5+
describe("throwOnIllegalChars", () => {
6+
7+
it("throws when the input does not match the pattern", () => {
8+
expect(throwOnIllegalChars("abc", '0-9', "Test")).toThrow(WidgetValidationError)
9+
})
10+
11+
it("does not throw when the input does match the pattern", () => {
12+
expect(throwOnIllegalChars("abc", 'a-z', "Test")).not.toThrow()
13+
})
14+
})
15+
16+
describe("throwOnNoMatch", () => {
17+
18+
it("throws when the input does not match the pattern", () => {
19+
expect(throwOnNoMatch("abc", /^$/, "Test")).toThrow(WidgetValidationError)
20+
})
21+
22+
it("does not throw when the input does match the pattern", () => {
23+
expect(throwOnNoMatch("abc", /[a-z]/, "Test")).not.toThrow()
24+
})
25+
})
26+
27+
})
28+

0 commit comments

Comments
 (0)