UNPKG

next-page-tester

Version:
54 lines (53 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); // https://github.com/vercel/next.js/issues/7479#issuecomment-659859682 function makeDefaultRouterMock({ pushHandler = () => { }, }) { const routerMock = { basePath: '', pathname: '/', route: '/', asPath: '/', query: {}, push: async (url, as, options) => { pushHandler(url, as, options); return true; }, replace: async (url, as, options) => { pushHandler(url, as, options); return true; }, reload: () => { }, back: () => { }, prefetch: async () => { }, beforePopState: () => { }, events: { on: () => { }, off: () => { }, emit: () => { }, }, isFallback: false, isLocaleDomain: false, isReady: true, isPreview: false, }; return routerMock; } function makeRouterMock({ options: { router: routerEnhancer }, pageObject, pushHandler, }) { const { pagePath, params, query, urlObject } = pageObject; const { pathname, search, hash } = urlObject; const { locales, defaultLocale, locale } = (0, utils_1.getLocales)({ pageObject }); const router = { ...makeDefaultRouterMock({ pushHandler }), asPath: pathname + search + hash, pathname: (0, utils_1.removeFileExtension)({ path: pagePath }), query: { ...params, ...query }, route: (0, utils_1.removeFileExtension)({ path: pagePath }), basePath: '', locales, defaultLocale, locale, }; return routerEnhancer(router); } exports.default = makeRouterMock;