sls-jest
  • Getting Started
  • Core Concepts
  • AWS Credentials
  • Matchers
    • DynamoDB
    • S3
    • AppSync
    • EventBridge
  • Spies
    • Setup
    • EventBridge
  • Utilities
    • DynamoDB
  • Cookbooks
    • Github Actions
    • CDK
Powered by GitBook
On this page
  • toExist()
  • toExistAndMatchObject<E>(expected: DeepPartial<E>)
  • toExistAndMatchSnapshot(propertiesOrHint?: string, hint?: string)
  • toExistAndMatchInlineSnapshot(propertiesOrHint?: string, hint?: string)

Was this helpful?

Edit on GitHub
  1. Matchers

S3

PreviousDynamoDBNextAppSync

Last updated 2 years ago

Was this helpful?

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 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 .

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)

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

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

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

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

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

node-retry
toMatchObject
toMatchSnapshot
toMatchInlineSnapshot