(no title)
anytime5704 | 1 year ago
expect(mockDynamoDBClient).toHaveReceivedAnyCommand(); // passes
expect(mockDynamoDBClient).toHaveReceivedCommand(UpdateCommand); // fails
Received number of calls: 2
Expected number of calls: >= 1
Expected command: UpdateCommand
Received commands:
- UpdateCommand
- UpdateCommand
I thought I was taking crazy pills.
asztal|1 year ago
Sadly, the most robust solution is often to use duck typing, e.g. instead of checking if the error is an instance of ResourceNotFoundError, check if error.code equals "ResourceNotFound" which works even if there are multiple library versions present. This is especially the case if you're writing a library that might be provided an instance of an AWS SDK v3 client, as it could be a different version.
I've been doing this stuff for 20 years so I'm used to it, I just feel bad for the novices.
anytime5704|1 year ago
I actually considered the looser validation when I discovered that toHaveReceivedAnyCommand() worked, but, ultimately decided there *had* to be something wrong with my setup and I refused to leave it to hit someone else.
Shame the AWS SDK doesn't communicate the actual error in a more human readable way. I was legitimately questioning my sanity and/or the validity of the library for a minute there.