Skip to main content
Testing infrastructure code ensures that your configurations are correct before they are deployed. tfts provides a Testing utility class to help you synthesize stacks and assert on the generated Terraform JSON.

The Testing Class

The Testing class is the primary entry point for writing tests in tfts. It provides methods for creating test applications, synthesizing stacks, and performing assertions.

Testing.app()

Creates a new App instance configured for testing.

Testing.synth()

Synthesizes a stack into a JSON object that can be used for assertions.

Testing.synthScope()

A helper method that creates a temporary scope, executes a callback to define resources, and returns the synthesized JSON.

Testing.synthToJson()

Synthesizes a stack and returns the result as a formatted JSON string.

Testing.renderConstructTree()

Returns a visual representation of the construct tree, which is useful for debugging complex hierarchies.

Assertions

tfts provides several assertion methods to verify the contents of the synthesized Terraform JSON.

Testing.toHaveResource()

Asserts that the JSON contains a resource of a specific type. You can optionally provide properties to match.

Testing.toHaveResourceWithProperties()

Similar to toHaveResource, but specifically emphasizes checking for a set of properties.

Testing.toHaveDataSource()

Asserts that the JSON contains a data source of a specific type.

Testing.toHaveProvider()

Asserts that the JSON contains a provider configuration.

Example Test File

Here is a complete example of a test file using bun:test.