Closed marcusds closed 4 weeks ago
For anyone else, I am working around this for now by doing:
await waitFor(() =>
expect(S3Mock).toHaveReceivedCommand(GetBucketPolicyCommand),
);
await waitFor(() => {
const args = S3Mock.commandCalls(GetBucketPolicyCommand)[0].args[0]
.input;
expect(args.Bucket).toStrictEqual('bucketName');
});
But its not ideal.
I'm hitting this problem too. I get TypeError: this.customTesters is not iterable
.
import 'aws-sdk-client-mock-jest'
import { BatchWriteCommand, DynamoDBDocumentClient, ScanCommand } from '@aws-sdk/lib-dynamodb'
import { mockClient } from 'aws-sdk-client-mock'
test('should...', async () => {
const docClientMock = mockClient(DynamoDBDocumentClient)
docClientMock.on(BatchWriteCommand).resolves({ ... })
await callProdCode()
expect(docClientMock).toHaveReceivedCommandTimes(BatchWriteCommand, 1) // ok
const batchWriteCalls = docClientMock.commandCalls(BatchWriteCommand)
const batchWriteInput = batchWriteCalls[0].args[0].input
// causes "TypeError: this.customTesters is not iterable" when test is run
expect(batchWriteInput).toMatchObject(expect.objectContaining({ ... }))
})
It seems to fall over somewhere matchers.js
when it tries to do
const pass = ...
...this.customTesters
If I don't import aws-sdk-client-mock-jest
//import 'aws-sdk-client-mock-jest'
then I get TypeError: expect(...).toHaveReceivedCommandTimes is not a function
and when I do import
import 'aws-sdk-client-mock-jest'
then I get TypeError: this.customTesters is not iterable
Hey,
the toHaveReceivedCommandWith
matcher already uses expect.objectContaining()
under the hood. You can use other asymmetric matchers for properties:
import 'aws-sdk-client-mock-jest';
import {mockClient} from "aws-sdk-client-mock";
import {PublishCommand, SNSClient} from "@aws-sdk/client-sns";
const sns = new SNSClient();
const snsMock = mockClient(SNSClient);
it('uses asymmetric matcher', async () => {
await sns.send(new PublishCommand({
TopicArn: 'arn:aws:sns:us-east-1:111111111111:MyTopic',
Message: 'hello world',
}));
expect(snsMock).toHaveReceivedCommandWith(
PublishCommand,
{
Message: expect.stringContaining('hello'),
},
);
});
I've added this to the README and docs. If I'm missing something, please reopen.
Checklist
Bug description
Hi, thank for this package - it is great.
However, Asymmetric Matchers such as
expect.objectContaining
orexpect.any(String)
don't appear to be working. The following example does not match.Example:
Am I doing something wrong? Or are they just not supported?
Reproduction
Environment