t.ctx Property
References the test context object. Each test has a test context object of its own. Store data within the test context object to share information between test hooks and the test body.
t.ctx → Object
You can completely redefine t.ctx
or simply add a property to the object:
fixture`TestController.ctx`
.beforeEach(async t => {
t.ctx.someProp = 123;
});
test('Check context', async t => {
await t.expect(t.ctx.someProp).eql(123); // > 123
}).after(async t => {
await t.expect(t.ctx.someProp).eql(123); // > 123
});
Note
t.ctx
is initialized with an empty object without a prototype. You can iterate its keys without the hasOwnProperty
check.