Can I mock functions with specific arguments using Jest?

I found this library that a colleague of mine wrote recently: jest-when

import { when } from 'jest-when';

const fn = jest.fn();
when(fn).calledWith(1).mockReturnValue('yay!');

const result = fn(1);
expect(result).toEqual('yay!');

Here’s the library: https://github.com/timkindberg/jest-when

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)