TestLogger
@algorandfoundation/algokit-utils / testing / TestLogger
testing.TestLogger
Exposes an AlgoKit logger which captures log messages, while wrapping an original logger. This is useful for automated testing.
Implements
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new TestLogger(originalLogger?
): TestLogger
Create a new test logger that wraps the given logger if provided.
Parameters
Name | Type | Description |
---|---|---|
originalLogger? | Logger | The optional original logger to wrap. |
Returns
Defined in
Properties
logs
• Private
logs: string
[]
Defined in
originalLogger
• Private
originalLogger: undefined
| Logger
Defined in
Accessors
capturedLogs
• get
capturedLogs(): string
[]
Returns all logs captured thus far.
Returns
string
[]
Defined in
Methods
clear
▸ clear(): void
Clears all logs captured so far.
Returns
void
Defined in
debug
▸ debug(message
, ...optionalParams
): void
Parameters
Name | Type |
---|---|
message | string |
...optionalParams | unknown [] |
Returns
void
Implementation of
Logger.debug
Defined in
error
▸ error(message
, ...optionalParams
): void
Parameters
Name | Type |
---|---|
message | string |
...optionalParams | unknown [] |
Returns
void
Implementation of
Logger.error
Defined in
getLogSnapshot
▸ getLogSnapshot(config?
): string
Returns a captured log snapshot. This helps ensure that the provided configuration items won’t appear with random values in the log snapshot, but rather will get substituted with predictable ids.
https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic
Parameters
Name | Type | Description |
---|---|---|
config? | LogSnapshotConfig | The snapshot configuration |
Returns
string
The snapshotted logs.
Example
const logger = new TestLogger()...expect(logger.getLogSnapshot()).toMatchSnapshot()
Defined in
info
▸ info(message
, ...optionalParams
): void
Parameters
Name | Type |
---|---|
message | string |
...optionalParams | unknown [] |
Returns
void
Implementation of
Logger.info
Defined in
verbose
▸ verbose(message
, ...optionalParams
): void
Parameters
Name | Type |
---|---|
message | string |
...optionalParams | unknown [] |
Returns
void
Implementation of
Logger.verbose
Defined in
warn
▸ warn(message
, ...optionalParams
): void
Parameters
Name | Type |
---|---|
message | string |
...optionalParams | unknown [] |
Returns
void
Implementation of
Logger.warn