Socket
Book a DemoInstallSign in
Socket

mock-nanoid

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-nanoid

Simple module meant to mock nanoid methods in a deterministic, sequential way for testing purposes.

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

mock-nanoid

Simple module meant to mock nanoid methods in a deterministic, sequential way for testing purposes.

import { nanoid } from 'nanoid/non-secure'

nanoid(5); // "V1StG"

Now you would do:

import { mockNanoid as nanoid } from 'mock-nanoid/non-secure';

nanoid(5); // '00000'
nanoid(5); // '00001'

nanoid(3); // '000'
nanoid(3); // '001'

nanoid.resetMock(5); // clears only length 5

nanoid(3); // '002'
nanoid(5); // '00002'

For mocks not yet built, we just re-export nanoid's functions.

To do this in jest:

// jest.config.mjs
import { createRequire } from 'module';
const require = createRequire(import.meta.url);

export default {
   // ...your configurations here
    moduleNameMapper: {
        // ...your other mocks here
        'nanoid': require.resolve('mock-nanoid'),
        'nanoid/non-secure': require.resolve('mock-nanoid/non-secure'),
    },
};

FAQs

Package last updated on 21 Apr 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.