@forge/react
11.18.0-next.011.18.0-next.1
out/router/utils/__test__/matchPath.test.js+
out/router/utils/__test__/matchPath.test.jsNew file+56
Index: package/out/router/utils/__test__/matchPath.test.js
===================================================================
--- package/out/router/utils/__test__/matchPath.test.js
+++ package/out/router/utils/__test__/matchPath.test.js
@@ -0,0 +1,56 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const matchPath_1 = require("../matchPath");
+describe('matchPath', () => {
+ it('matches exact static paths', () => {
+ expect((0, matchPath_1.matchPath)('/', '/')).toEqual({ params: {} });
+ expect((0, matchPath_1.matchPath)('/settings', '/settings')).toEqual({ params: {} });
+ });
+ it('returns null for non-matching static paths', () => {
+ expect((0, matchPath_1.matchPath)('/settings', '/about')).toBeNull();
+ expect((0, matchPath_1.matchPath)('/settings', '/')).toBeNull();
+ });
+ it('extracts a single param', () => {
+ expect((0, matchPath_1.matchPath)('/posts/:id', '/posts/123')).toEqual({ params: { id: '123' } });
+ });
+ it('extracts multiple params', () => {
+ expect((0, matchPath_1.matchPath)('/posts/:postId/comments/:commentId', '/posts/42/comments/7')).toEqual({
+ params: { postId: '42', commentId: '7' }
+ });
+ });
+ it('returns null when segment count differs', () => {
+ expect((0, matchPath_1.matchPath)('/posts/:id', '/posts')).toBeNull();
+ expect((0, matchPath_1.matchPath)('/posts/:id', '/posts/123/extra')).toBeNull();
+ });
+ it('returns null when static segments do not match', () => {
+ expect((0, matchPath_1.matchPath)('/posts/:id', '/users/123')).toBeNull();
+ });
+ it('matches paths with mixed static and dynamic segments', () => {
+ expect((0, matchPath_1.matchPath)('/users/:userId/posts/:postId', '/users/alice/posts/99')).toEqual({
+ params: { userId: 'alice', postId: '99' }
+ });
+ });
+ it('matches catchall pattern and captures remaining segments', () => {
+ expect((0, matchPath_1.matchPath)('/files/*', '/files/docs/report.pdf')).toEqual({
+ params: { '*': 'docs/report.pdf' }
+ });
+ });
+ it('matches catchall with empty remainder', () => {
+ expect((0, matchPath_1.matchPath)('/files/*', '/files')).toEqual({
+ params: { '*': '' }
+ });
+ });
+ it('matches bare catchall against any path', () => {
+ expect((0, matchPath_1.matchPath)('*', '/anything/at/all')).toEqual({
+ params: { '*': 'anything/at/all' }
+ });
+ });
+ it('matches catchall combined with dynamic params', () => {
+ expect((0, matchPath_1.matchPath)('/posts/:id/*', '/posts/42/comments/7')).toEqual({
+ params: { id: '42', '*': 'comments/7' }
+ });
+ });
+ it('returns null when static segments before catchall do not match', () => {
+ expect((0, matchPath_1.matchPath)('/files/*', '/users/alice')).toBeNull();
+ });
+});