Skip to content

创建文章

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

testing.TestLogger

@algorandfoundation/algokit-utils / testing / TestLogger

Class: 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

TestLogger

Defined in

src/testing/test-logger.ts:16

Properties

logs

Private logs: string[]

Defined in

src/testing/test-logger.ts:10


originalLogger

Private originalLogger: undefined | Logger

Defined in

src/testing/test-logger.ts:9

Accessors

capturedLogs

get capturedLogs(): string[]

Returns all logs captured thus far.

Returns

string[]

Defined in

src/testing/test-logger.ts:22

Methods

clear

clear(): void

Clears all logs captured so far.

Returns

void

Defined in

src/testing/test-logger.ts:27


debug

debug(message, ...optionalParams): void

Parameters
Name Type
message string
...optionalParams unknown[]
Returns

void

Implementation of

Logger.debug

Defined in

src/testing/test-logger.ts:77


error

error(message, ...optionalParams): void

Parameters
Name Type
message string
...optionalParams unknown[]
Returns

void

Implementation of

Logger.error

Defined in

src/testing/test-logger.ts:61


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

src/testing/test-logger.ts:47


info

info(message, ...optionalParams): void

Parameters
Name Type
message string
...optionalParams unknown[]
Returns

void

Implementation of

Logger.info

Defined in

src/testing/test-logger.ts:69


verbose

verbose(message, ...optionalParams): void

Parameters
Name Type
message string
...optionalParams unknown[]
Returns

void

Implementation of

Logger.verbose

Defined in

src/testing/test-logger.ts:73


warn

warn(message, ...optionalParams): void

Parameters
Name Type
message string
...optionalParams unknown[]
Returns

void

Implementation of

Logger.warn

Defined in

src/testing/test-logger.ts:65