mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
fix: update definition to match wtih jest-when@2.4.1 (#34755)
This commit is contained in:
parent
bea39a0360
commit
b497be0de0
5
types/jest-when/index.d.ts
vendored
5
types/jest-when/index.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
// Type definitions for jest-when 1.1
|
||||
// Type definitions for jest-when 2.4
|
||||
// Project: https://github.com/timkindberg/jest-when#readme
|
||||
// Definitions by: Alden Taylor <https://github.com/aldentaylor>
|
||||
// Trung Dang <https://github.com/immanuel192>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
@ -15,6 +16,8 @@ export interface WhenMock<T = any, Y extends any[] = any> extends jest.Mock<T, Y
|
||||
mockResolvedValueOnce(value: jest.ResolvedValue<T>): WhenMock<T, Y>;
|
||||
mockRejectedValue(value: jest.RejectedValue<T>): WhenMock<T, Y>;
|
||||
mockRejectedValueOnce(value: jest.RejectedValue<T>): WhenMock<T, Y>;
|
||||
mockImplementation(fn: (...args: Y) => T): WhenMock<T, Y>;
|
||||
mockImplementationOnce(fn?: (...args: Y) => T): WhenMock<T, Y>;
|
||||
}
|
||||
|
||||
export type When = <T, Y extends any[]>(fn: jest.Mock<T, Y>) => WhenMock<T, Y>;
|
||||
|
||||
@ -89,4 +89,28 @@ describe('mock-when test', () => {
|
||||
}
|
||||
expect(testPassed).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support for mockImplementation', () => {
|
||||
const fn = jest.fn();
|
||||
const expectValue = { a: 1, b: 2 };
|
||||
when(fn).calledWith(
|
||||
expect.anything()
|
||||
).mockImplementation(() => (expectValue));
|
||||
|
||||
const result = fn('whatever');
|
||||
expect(result).toMatchObject(expectValue);
|
||||
});
|
||||
|
||||
it('should support for mockImplementationOnce', () => {
|
||||
const fn = jest.fn();
|
||||
const expectValue = { a: 1, b: 2 };
|
||||
when(fn).calledWith(
|
||||
expect.anything()
|
||||
).mockImplementationOnce(() => (expectValue));
|
||||
|
||||
const result = fn('whatever');
|
||||
const result2 = fn('whatever');
|
||||
expect(result).toMatchObject(expectValue);
|
||||
expect(result2).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user