Socket
Socket
Sign inDemoInstall

next-router-mock

Package Overview
Dependencies
Maintainers
1
Versions
51
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


Version published
Weekly downloads
548K
increased by4.66%
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

FAQs

Package last updated on 23 Dec 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc