Skip to content

AlgorandFixture

@algorandfoundation/algokit-utils / types/testing / AlgorandFixture

types/testing.AlgorandFixture

An Algorand automated testing fixture

beforeEach: () => Promise<void>

Deprecated

Use newScope instead. Testing framework agnostic handler method to run before each test to prepare the context for that test with per test isolation.

▸ (): Promise<void>

Promise<void>

src/types/testing.ts:90


newScope: () => Promise<void>

Creates a new isolated fixture scope (clean transaction logger, AlgorandClient, testAccount, etc.).

You can call this from any testing framework specific hook method to control when you want a new scope.

Example

describe('MY MODULE', () => {
const fixture = algorandFixture();
beforeEach(fixture.newScope, 10_000); // Add a 10s timeout to cater for occasionally slow LocalNet calls
test('MY TEST', async () => {
const { algorand, testAccount } = fixture.context;
// Test stuff!
});
});

Example

describe('MY MODULE', () => {
const fixture = algorandFixture();
beforeAll(fixture.newScope, 10_000); // Add a 10s timeout to cater for occasionally slow LocalNet calls
test('test1', async () => {
const { algorand, testAccount } = fixture.context;
// Test stuff!
});
test('test2', async () => {
const { algorand, testAccount } = fixture.context;
// algorand and testAccount are the same as in test1
});
});

▸ (): Promise<void>

Promise<void>

src/types/testing.ts:130

get algorand(): AlgorandClient

Retrieve an AlgorandClient loaded with the current context, including testAccount and any generated accounts loaded as signers.

AlgorandClient

src/types/testing.ts:84


get context(): AlgorandTestAutomationContext

Retrieve the current context. Useful with destructuring.

If you haven’t called newScope then this will throw an error.

AlgorandTestAutomationContext

Example

test('My test', () => {
const {algod, indexer, testAccount, ...} = fixture.context
})

src/types/testing.ts:79