Skip to content
Go to file
7 contributors

Users who have contributed to this file

@novemberborn @yjpa7145 @tymfear @dflupu @ulken @forresst @bunysae
75 lines (47 sloc) 2.33 KB

Execution Context (t argument)

Translations: Français

Each test or hook is called with an execution context. By convention it's named t.

const test = require('ava');

test('my passing test', t => {

Each test or hook receives a different object. It contains the assertions as well as the methods and properties listed below.


The test title.


Contains shared state from hooks.


When used in test.afterEach() or test.afterEach.always() hooks this tells you whether the test has passed. When used in a test itself (including teardown functions) this remains true until an assertion fails, the test has ended with an error, or a teardown function caused an error. This value has no meaning in other hooks.


End the test. Only works with test.cb().


Log values contextually alongside the test result instead of immediately printing them to stdout. Behaves somewhat like console.log, but without support for placeholder tokens.


Plan how many assertions there are in the test. The test will fail if the actual assertion count doesn't match the number of planned assertions. See assertion planning.


Registers the fn function to be run after the test has finished. You can register multiple functions and they'll run in order. You can use asynchronous functions: only one will run at a time.

You cannot perform assertions using the t object or register additional functions from inside fn.

You cannot use t.teardown() in hooks either.

In the next major release we'll change this so teardown functions run in reverse order. The last registered function will be called first. You can opt in to this behavior now by enabling the reverseTeardowns experiment.


	"ava": {
		"nonSemVerExperiments": {
			"reverseTeardowns": true


export default {
	nonSemVerExperiments: {
		reverseTeardowns: true


Set a timeout for the test, in milliseconds. The test will fail if this timeout is exceeded. The timeout is reset each time an assertion is made.

You can’t perform that action at this time.