11import { describe , it , expect } from "vitest" ;
2- import { parse , compile , match , stringify } from "./index.js" ;
2+ import {
3+ parse ,
4+ compile ,
5+ match ,
6+ stringify ,
7+ pathToRegexp ,
8+ TokenData ,
9+ } from "./index.js" ;
310import {
411 PARSER_TESTS ,
512 COMPILE_TESTS ,
@@ -19,6 +26,7 @@ describe("path-to-regexp", () => {
1926 ) ,
2027 ) ;
2128 } ) ;
29+
2230 it ( "should throw on nested unbalanced group" , ( ) => {
2331 expect ( ( ) => parse ( "/{:foo/{x,y}" ) ) . toThrow (
2432 new TypeError (
@@ -94,6 +102,49 @@ describe("path-to-regexp", () => {
94102 } ) ;
95103 } ) ;
96104
105+ describe ( "pathToRegexp errors" , ( ) => {
106+ it ( "should throw when missing text between params" , ( ) => {
107+ expect ( ( ) => pathToRegexp ( "/:foo:bar" ) ) . toThrow (
108+ new TypeError (
109+ 'Missing text before "bar": /:foo:bar; visit https://git.new/pathToRegexpError for more info' ,
110+ ) ,
111+ ) ;
112+ } ) ;
113+
114+ it ( "should throw when missing text between params using TokenData" , ( ) => {
115+ expect ( ( ) =>
116+ pathToRegexp (
117+ new TokenData ( [
118+ { type : "param" , name : "a" } ,
119+ { type : "param" , name : "b" } ,
120+ ] ) ,
121+ ) ,
122+ ) . toThrow (
123+ new TypeError (
124+ 'Missing text before "b"; visit https://git.new/pathToRegexpError for more info' ,
125+ ) ,
126+ ) ;
127+ } ) ;
128+
129+ it ( "should throw with `originalPath` when missing text between params using TokenData" , ( ) => {
130+ expect ( ( ) =>
131+ pathToRegexp (
132+ new TokenData (
133+ [
134+ { type : "param" , name : "a" } ,
135+ { type : "param" , name : "b" } ,
136+ ] ,
137+ "/[a][b]" ,
138+ ) ,
139+ ) ,
140+ ) . toThrow (
141+ new TypeError (
142+ 'Missing text before "b": /[a][b]; visit https://git.new/pathToRegexpError for more info' ,
143+ ) ,
144+ ) ;
145+ } ) ;
146+ } ) ;
147+
97148 describe . each ( PARSER_TESTS ) (
98149 "parse $path with $options" ,
99150 ( { path, options, expected } ) => {
0 commit comments