Do you want to request a feature or report a bug?
feature
What is the current behavior?
we can throw errors using mockImplementation
.
mockFn.mockImplementation(() => { throw new Error('adbd') });
mockFn.mockImplementationOnce(() => { throw new TypeError('adbd') });
but, ideally i'd like to see something like:
mockFn.mockThrowError('adbd');
mockFn.mockThrowErrorOnce(new TypeError('adbd'));
What is the expected behavior?
testcase:
it('supports throw errors', () => {
const fn = moduleMocker.getMockFunction();
fn.mockThrowError('abcd');
expect(fn).toThrowError('abcd');
const fn2 = moduleMocker.getMockFunction();
fn.mockThrowError(new TypeError('abcd'));
expect(fn2).toThrowError(TypeError);
});
Since you can write a one-liner function/wrapper around it, I don't see the reason for extending mocks API just to do this.
I'm closing the issue for now to manage the queue, but we can keep the discussion going and reopen if necessary.