Giter Club home page Giter Club logo

Comments (3)

marcusds avatar marcusds commented on June 30, 2024

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.

mikhoq avatar mikhoq commented on June 30, 2024

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.

m-radzikowski avatar m-radzikowski commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.