jest-mock-process

  • Version 2.0.0
  • Published
  • 16.4 kB
  • No dependencies
  • MIT license

Install

npm i jest-mock-process
yarn add jest-mock-process
pnpm add jest-mock-process

Overview

Easily mock NodeJS process properties in Jest

Index

Functions

function asyncMockedRun

asyncMockedRun: <T extends JestCallableMocksObject, R>(
callers: T
) => (f: () => Promise<R>) => Promise<MockedRunResult<R, JestMocksObject<T>>>;
  • Helper function to run an asynchronous function with provided mocks in place, as a virtual environment.

    Every provided mock will be automatically restored when this function returns.

function mockConsoleLog

mockConsoleLog: () => jest.SpyInstance<
void,
[message?: any, ...optionalParams: any[]]
>;
  • Helper function to create a mock of the Node.js method console.log(message: any).

function mockedRun

mockedRun: <T extends JestCallableMocksObject, R>(
callers: T
) => (f: () => R) => MockedRunResult<R, JestMocksObject<T>>;
  • Helper function to run a synchronous function with provided mocks in place, as a virtual environment.

    Every provided mock will be automatically restored when this function returns.

function mockProcessExit

mockProcessExit: (err?: any) => jest.SpyInstance<never, [code?: number]>;
  • Helper function to create a mock of the Node.js method process.exit(code: number).

    Parameter err

    Optional error to raise. If unspecified or falsy, calling process.exit will resume code execution instead of raising an error.

function mockProcessStderr

mockProcessStderr: () => jest.SpyInstance<
Required<boolean>,
[str: string, encoding?: string, cb?: Function]
>;
  • Helper function to create a mock of the Node.js method process.stderr.write(text: string, callback?: function): boolean.

function mockProcessStdout

mockProcessStdout: () => jest.SpyInstance<
Required<boolean>,
[str: string, encoding?: string, cb?: Function]
>;
  • Helper function to create a mock of the Node.js method process.stdout.write(text: string, callback?: function): boolean.

function mockProcessUptime

mockProcessUptime: (value?: number) => jest.SpyInstance<number, []>;
  • Helper function to create a mock of the Node.js method process.uptime().

function spyOnImplementing

spyOnImplementing: <
T extends {},
M extends JMPFunctionPropertyNames<T>,
F extends T[M],
I extends (...args: any[]) => JMPReturnType<F>
>(
target: T,
property: M,
impl: I
) => jest.SpyInstance<Required<JMPReturnType<F>>, JMPArgsType<F>>;
  • Helper function for manually creating new spy mocks of functions not supported by this module.

    Parameter target

    Object containing the function that will be mocked.

    Parameter property

    Name of the function that will be mocked.

    Parameter impl

    Mock implementation of the target's function. The return type must match the target function's.

Interfaces

interface MockedRunResult

interface MockedRunResult<R, M> {}

    property error

    error?: any;

      property mocks

      mocks: M;

        property result

        result?: R;

          Package Files (1)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (6)

          Peer Dependencies (1)

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-mock-process.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jest-mock-process)
          • HTML
            <a href="https://www.jsdocs.io/package/jest-mock-process"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>