TestConsole
Provides a test implementation of the Effect Console service.
When the test layer is provided, calls made through the Effect console APIs are captured in memory instead of being written to the host console. Tests can then assert on logged values deterministically. This module includes the console layer, helpers for reading captured Console.log and Console.error arguments, and access to the provided test console service.
Constructors
Layers
Creates a Layer which constructs a TestConsole. This layer can be used to provide a TestConsole implementation for testing purposes.
When to use
Use to run an effect with console calls captured by TestConsole.
See
makefor constructing the service value directlytestConsoleWithfor accessing the provided test console service
Signature
declare const layer: Layer.Layer<TestConsole>;Models
TestConsole interface
A TestConsole provides a testable implementation of the Console interface. It captures all console output for testing purposes while maintaining full compatibility with the standard Console API.
When to use
Use to provide a console implementation that records calls for assertions in tests.
Details
This interface extends the standard Console interface and adds methods to retrieve logged messages for verification in tests.
See
layerfor providingTestConsoleto an effectlogLinesfor reading capturedConsole.logcallserrorLinesfor reading capturedConsole.errorcalls
Signature
interface TestConsole extends Console {
readonly errorLines: Effect<readonly Array<unknown>>;
readonly logLines: Effect<readonly Array<unknown>>;
}Other
TestConsole
The TestConsole namespace provides types and utilities for working with test console implementations.
When to use
Use when referring to types nested under the TestConsole namespace.
Testing
errorLines
Returns an array of all items that have been logged by the program using Console.error thus far.
When to use
Use to assert on captured Console.error output from a program provided with TestConsole.layer.
See
Signature
declare const errorLines: Effect.Effect<ReadonlyArray<unknown>, never, never>;Returns an array of all items that have been logged by the program using Console.log thus far.
When to use
Use to assert on captured Console.log output from a program provided with TestConsole.layer.
See
errorLinesfor reading capturedConsole.erroroutputlayerfor capturing console calls during a test
Signature
declare const logLines: Effect.Effect<ReadonlyArray<unknown>, never, never>;testConsoleWith
Retrieves the TestConsole service for this test and uses it to run the specified workflow.
When to use
Use to access the provided test console service inside an effect.
See
layerfor providing the test console servicelogLinesfor reading capturedConsole.logcalls directlyerrorLinesfor reading capturedConsole.errorcalls directly
Signature
declare function testConsoleWith<A, E, R>(
f: (console: TestConsole) => Effect<A, E, R>,
): Effect<A, E, R>;
Creates a new TestConsole instance that captures all console output. The returned TestConsole implements the Console interface and provides additional methods to retrieve logged messages.
When to use
Use to construct a test console service value directly.
See
layerfor providing aTestConsoleas aLayer