3.5.5 • Published 6 months ago

@types/jest-when v3.5.5

Weekly downloads
63,688
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/jest-when

Summary

This package contains type definitions for jest-when (https://github.com/timkindberg/jest-when#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest-when.

index.d.ts

// Type definitions for jest-when 3.5
// Project: https://github.com/timkindberg/jest-when#readme
// Definitions by: Alden Taylor <https://github.com/aldentaylor>
//                 Trung Dang <https://github.com/immanuel192>
//                 Gregor Stamać <https://github.com/gstamac>
//                 Nicholas Hehr <https://github.com/hipsterbrown>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.8

/// <reference types="jest" />

export type ArgumentOrMatcher<ArgTypes extends any[]> = {
    [Index in keyof ArgTypes]: ArgTypes[Index] | WhenMock<boolean, [ArgTypes[Index]]>;
};

export interface WhenMock<T = any, Y extends any[] = any> extends jest.MockInstance<T, Y> {
    calledWith(allArgsMatcher: AllArgsMatcher<Y>): this;
    calledWith(...matchers: ArgumentOrMatcher<Y>): this;
    expectCalledWith(allArgsMatcher: AllArgsMatcher<Y>): this;
    expectCalledWith(...matchers: ArgumentOrMatcher<Y>): this;
    mockReturnValue(value: T): this;
    mockReturnValueOnce(value: T): this;
    mockResolvedValue(value: jest.ResolvedValue<T>): this;
    mockResolvedValueOnce(value: jest.ResolvedValue<T>): this;
    mockRejectedValue(value: jest.RejectedValue<T>): this;
    mockRejectedValueOnce(value: jest.RejectedValue<T>): this;
    mockImplementation(fn: (...args: Y) => T): this;
    mockImplementationOnce(fn?: (...args: Y) => T): this;
    defaultReturnValue(value: T): this;
    defaultResolvedValue(value: jest.ResolvedValue<T>): this;
    defaultRejectedValue(value: jest.RejectedValue<T>): this;
    defaultImplementation(fn: (...args: Y) => T): this;
}

export interface AllArgsMatcher<Y> {
    (args: Y, equals: jest.MatcherUtils['equals']): boolean;
    // Internal, but needed to distinguish from normal callables
    _isAllArgsFunctionMatcher: true;
    _isFunctionMatcher: true;
}

export interface When {
    <T, Y extends any[]>(fn: ((...args: Y) => T) | jest.MockInstance<T, Y>): WhenMock<T, Y>;

    allArgs<Y extends any[]>(matcher: (args: Y, equals: jest.MatcherUtils['equals']) => boolean): AllArgsMatcher<Y>;
}

export const when: When;
export function resetAllWhenMocks(): void;
export function verifyAllWhenMocksCalled(): void;

Additional Details

  • Last updated: Tue, 01 Feb 2022 21:01:25 GMT
  • Dependencies: @types/jest
  • Global values: none

Credits

These definitions were written by Alden Taylor, Trung Dang, Gregor Stamać, and Nicholas Hehr.

3.5.3

8 months ago

3.5.5

6 months ago

3.5.4

7 months ago

3.5.2

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

2.7.4

2 years ago

2.7.3

3 years ago

2.7.2

4 years ago

2.7.1

4 years ago

2.7.0

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago