🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

next-router-mock

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-router-mock

Mock implementation of the Next.js Router

1.0.2
latest
Source
npm
Version published
Weekly downloads
643K
-2.28%
Maintainers
1
Weekly downloads
 
Created

What is next-router-mock?

The next-router-mock package is a mock implementation of Next.js's router, designed for testing purposes. It allows developers to simulate and test routing behavior in their Next.js applications without needing to run a full Next.js server.

What are next-router-mock's main functionalities?

Mocking push method

This feature allows you to mock the push method of the Next.js router, enabling you to simulate navigation to a new route in your tests.

const { useRouter } = require('next/router');
const mockRouter = require('next-router-mock');

mockRouter.push('/new-route');

console.log(mockRouter.pathname); // Output: /new-route

Mocking query parameters

This feature allows you to mock query parameters in the Next.js router, enabling you to test components that rely on query parameters.

const { useRouter } = require('next/router');
const mockRouter = require('next-router-mock');

mockRouter.push({ pathname: '/new-route', query: { id: '123' } });

console.log(mockRouter.query.id); // Output: 123

Mocking back method

This feature allows you to mock the back method of the Next.js router, enabling you to simulate the user navigating back to the previous route.

const { useRouter } = require('next/router');
const mockRouter = require('next-router-mock');

mockRouter.push('/first-route');
mockRouter.push('/second-route');
mockRouter.back();

console.log(mockRouter.pathname); // Output: /first-route

Other packages similar to next-router-mock

Keywords

react

FAQs

Package last updated on 12 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts