Skip to content

Commit f0b30bb

Browse files
committed
Add coverage for errors
1 parent a1cfa60 commit f0b30bb

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/index.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,24 @@ describe("path-to-regexp", () => {
27662766
pathToRegexp.pathToRegexp("/foo?");
27672767
}).toThrow(new TypeError("Unexpected MODIFIER at 4, expected END"));
27682768
});
2769+
2770+
it("should throw on parameters without text between them", () => {
2771+
expect(() => {
2772+
pathToRegexp.pathToRegexp("/:x:y");
2773+
}).toThrow(
2774+
new TypeError(
2775+
`Must have text between two parameters, missing text after "x"`,
2776+
),
2777+
);
2778+
});
2779+
2780+
it("should throw on unrepeatable params", () => {
2781+
expect(() => {
2782+
pathToRegexp.pathToRegexp("/foo:x*");
2783+
}).toThrow(
2784+
new TypeError(`Can not repeat "x" without a prefix and suffix`),
2785+
);
2786+
});
27692787
});
27702788

27712789
describe("tokens", () => {

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
176176

177177
if (prev && !prevText) {
178178
throw new TypeError(
179-
`No support for parameters without text between them after "${(prev as Key).name}"`,
179+
`Must have text between two parameters, missing text after "${(prev as Key).name}"`,
180180
);
181181
}
182182

@@ -583,7 +583,7 @@ export function tokensToRegexp(
583583
} else {
584584
if (token.modifier === "+" || token.modifier === "*") {
585585
throw new TypeError(
586-
`Can not repeat ${token.name} with no prefix or suffix, e.g. "/:param${token.modifier}"`,
586+
`Can not repeat "${token.name}" without a prefix and suffix`,
587587
);
588588
}
589589

0 commit comments

Comments
 (0)