Comments (3)
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.
from aws-sdk-client-mock.
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
from aws-sdk-client-mock.
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.
from aws-sdk-client-mock.
Related Issues (20)
- Testing SDK Retries HOT 3
- Upload throws error when using mocked S3 client HOT 3
- Types is not working for aws-sdk 3.362.0 HOT 4
- AwsStub issues HOT 3
- SQSClient received matching "DeleteMessageCommand" 0 times, after "SendMessageCommand" is run HOT 1
- NodeJS 20 mocking Upload doesn't work HOT 1
- Question: how to list/print configured client beheviours? HOT 1
- calls() does not return calls made from exception handler HOT 1
- 3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith on vitest HOT 3
- Jest matcher expect().toEqual() throws error "TypeError: this.customTesters is not iterable" HOT 4
- s3 mock: You are trying to `import` a file after the Jest environment has been torn down. HOT 2
- Documentation for callsFake() should provide an example of returning Promise.reject() HOT 1
- Mocked ECSClient (using mockClient(ECSClient)) is not assignable to parameter of type 'ECSClient' HOT 10
- .toHaveReceivedCommandWith ignoring DeleteCommand and ScanCommand HOT 1
- remock support (or clarity on the pattern) HOT 1
- "Not Assignable to type" error trying to mock S3 GetObject for Binary File.
- Can't get Upload mock to work for small files HOT 3
- Documentation example for __mocks__ implementation
- aws-sdk-client-mock-jest with CommonJs?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-client-mock.