mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-10-30 14:49:14 +00:00
36 lines
822 B
TypeScript
36 lines
822 B
TypeScript
import type {InjectedRouter} from 'react-router';
|
|
import {stringify} from 'query-string';
|
|
import {LocationFixture} from 'sentry-fixture/locationFixture';
|
|
|
|
export function RouterFixture(params = {}): InjectedRouter {
|
|
return {
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
go: jest.fn(),
|
|
goBack: jest.fn(),
|
|
goForward: jest.fn(),
|
|
setRouteLeaveHook: jest.fn(),
|
|
isActive: jest.fn(),
|
|
createHref: jest.fn().mockImplementation(to => {
|
|
if (typeof to === 'string') {
|
|
return to;
|
|
}
|
|
|
|
if (typeof to === 'object') {
|
|
if (!to.query) {
|
|
return to.pathname;
|
|
}
|
|
|
|
return `${to.pathname}?${stringify(to.query)}`;
|
|
}
|
|
|
|
return '';
|
|
}),
|
|
location: LocationFixture(),
|
|
createPath: jest.fn(),
|
|
routes: [],
|
|
params: {},
|
|
...params,
|
|
};
|
|
}
|