Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow throwing errors in callsFake() mock #8

Closed
m-radzikowski opened this issue Mar 6, 2021 · 2 comments
Closed

Allow throwing errors in callsFake() mock #8

m-radzikowski opened this issue Mar 6, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@m-radzikowski
Copy link
Owner

Currently, the callsFake() mock does not support throwing an error from it. The error should be returned as a Client send() error, in the same way as mock.rejects() behaves.


Please vote with 👍   if you need this.

@m-radzikowski m-radzikowski added the enhancement New feature or request label Mar 6, 2021
@bgardner-noggin
Copy link

I managed to get this to work for my code

let getParameters;
iamMock.on(GetSAMLProviderCommand.callsFake((input) => {
 getParameters = input;
 throw Error('forcing error');
});
...
expect(getParameters.Name).toEqual('Foo');

@m-radzikowski
Copy link
Owner Author

@bgardner-noggin this throws an error from the test that is not caught by jest, so this test fails with an error:

it('throws an error', async () => {
    snsMock.on(PublishCommand).callsFake(() => {
        throw new Error('forcing error');
    });

    const sns = new SNSClient({});

    await expect(sns.send(publishCmd1)).rejects.toThrow('forcing error');
});

However, this nudged me to look into handling errors from callsFake(), and I've just added it and released as v2.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants