S3

A collection of matchers that you can use to assert on S3 bucket objects.

Use the s3Object() helper function to specify which S3 object you are testing. It takes the following input parameters:

  • bucketName: The bucket name where the object should be found.

  • key: They key of the object you are looking for

  • retryPolicy: An optional node-retry options config. sls-jest will retry using the given retry policy until the test passes or all the retries are exhausted. This is useful in an asynchronous context.

toExist()

Asserts whether an S3 object exists in the given bucket.

await expect(
  s3Object({
    bucketName: 'my-bucket',
    key: 'path/to/file.txt',
  }),
).toExist();

toExistAndMatchObject<E>(expected: DeepPartial<E>)

Asserts that an object exists in the given bucket, and matches a subset of the properties of a javascript object. It works similarly to jest's toMatchObject.

Note: This matcher can only be used with S3 objects that contain JSON-like data. If the content of the file cannot be parsed to a valid JSON, an error will be thrown.

await expect(
  s3Object({
    bucketName: 'my-bucket',
    key: 'path/to/file.txt',
  }),
).toExistAndMatchObject<Message>({
  message: 'Hello world!',
});

toExistAndMatchSnapshot(propertiesOrHint?: string, hint?: string)

Asserts that an item exists in the given bucket, and that it matches the most recent snapshot. It works similarly to jest's toMatchSnapshot.

await expect(
  s3Object({
    bucketName: 'my-bucket',
    key: 'path/to/file.txt',
  }),
).toExistAndMatchSnapshot();

toExistAndMatchInlineSnapshot(propertiesOrHint?: string, hint?: string)

Asserts that an object exists in the given bucket, and that it matches the most recent inline snapshot. It works similarly to jest's toMatchInlineSnapshot.

await expect(
  s3Object({
    bucketName: 'my-bucket',
    key: 'path/to/file.txt',
  }),
).toExistAndMatchInlineSnapshot(`
  Object {
    "message": 'Hello world!',
  }
`);

Last updated