You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've stumbled upon an issue where Jest is not clear to me and throw's an invalid error without a message:
Error: expect(jest.fn()).toHaveBeenLastCalledWith(expected)
Expected mock function to have been last called with:
368 | it('Should call the storage assignRole method with the right parameters', () => {
369 | Privileges.assignRole('chris', 'admin');
> 370 | expect(mockStorage.assignRole).toHaveBeenLastCalledWith('chris', 'admin');
371 | });
372 | });
373 |
at Object.it (lib/privileges.test.js:370:38)
After some research I found out that the error is thrown, because i'm pushing a 3th parameter with an undefined value into my jest mock function like shown below:
// Calling this method with assignRole('chris', 'admin')
assignRole(userId, role, group) {
// Below 'assignRole' method call is mocked. group === undefined
return this.storage.assignRole(userId, role, group);
}
On the other hand, testing it with explicitly checking for undefined will result in a valid test:
it('Should call the storage assignRole method with the right parameters', () => {
Privileges.assignRole('chris', 'admin');
expect(mockStorage.assignRole).toHaveBeenLastCalledWith('chris', 'admin', undefined);
});
I would expect Jest not to throw any error when I'm not checking the 3th parameter. If it does need to throw any error, because I am passing the group parameter (explicitly checking all parameters) then I would expect Jest to throw me an error along the lines of "Expected mock function to have been last called with 2 parameters. Instead it was called with 3."
I'm using the latest Jest version "22.1.4".
Thank you!
The text was updated successfully, but these errors were encountered:
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
I've stumbled upon an issue where Jest is not clear to me and throw's an invalid error without a message:
After some research I found out that the error is thrown, because i'm pushing a 3th parameter with an undefined value into my jest mock function like shown below:
On the other hand, testing it with explicitly checking for undefined will result in a valid test:
I would expect Jest not to throw any error when I'm not checking the 3th parameter. If it does need to throw any error, because I am passing the group parameter (explicitly checking all parameters) then I would expect Jest to throw me an error along the lines of "Expected mock function to have been last called with 2 parameters. Instead it was called with 3."
I'm using the latest Jest version "22.1.4".
Thank you!
The text was updated successfully, but these errors were encountered: