-
Notifications
You must be signed in to change notification settings - Fork 40
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
expect.assertions() is not the expected number when using toHaveReceivedCommandWith #122
Comments
With the same Jest and TS version, I did run this test: import {mockClient} from 'aws-sdk-client-mock';
import 'aws-sdk-client-mock-jest';
import {PublishCommand, SNSClient} from '@aws-sdk/client-sns';
const snsMock = mockClient(SNSClient);
it('asserts 1 time', async () => {
expect.assertions(1);
const sns = new SNSClient({});
await sns.send(new PublishCommand({TopicArn: '', Message: ''}));
expect(snsMock).toHaveReceivedCommand(PublishCommand);
}); and it works fine. Please double-check your code and, if the problem preserves, create a small repo with reproduction. |
Please try it with toHaveReceivedCommandWith, that's the one that within the function itself calls expect, which I suspect is the why there is an extra assertion.
|
Sorry, yes, you are right. The problem is with the I will check if it's possible to easily get rid of it to get the assertions number check working correctly. |
What do you think if all calls of
Could be replaced with e.g. deep-equal library? More specifically in aws-sdk-client-mock/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts Lines 274 to 276 in 4a96d34
aws-sdk-client-mock/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts Lines 321 to 323 in 4a96d34
If the equality is not met, we could manually return jest like error messages stating where the issue is. Or is there a way to use the current expect implementation from Jest without increasing the count of assertions? To consider: as the v2 has been out some time, this would be a breaking change and major version bump should probably be made, even when it is fixing regression in v2. |
The currently used If you are willing to submit a PR, I would gladly review it. Re version and breaking change... https://xkcd.com/1172/ But I guess there is no harm in bumping the major version, why not. |
Added a potential PR to fix this behaviour. Didn't bump any versions :) |
Released in v4.0.0. Thank you @lobbin! |
Checklist
Bug description
After upgrading to version 2 and using the separate package for jest matchers, tests that are using an expect of toHaveReceivedCommandWith are now failing because the number of expects is now coming out as 1 higher than it was previously.
Reproduction
e.g.
Will give this error:
Expected one assertion to be called but received two assertion calls
I am wondering if it is because toHaveReceivedCommandWith itself contains an expect call inside the function, and that is now being added to the number of expects called.
Environment
The text was updated successfully, but these errors were encountered: