Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 1.06 KB

hooks-order.md

File metadata and controls

81 lines (58 loc) · 1.06 KB

Enforce test hook ordering

Translations: Français

Hooks should be placed before any tests and in the proper semantic order:

  • test.before(…);
  • test.after(…);
  • test.after.always(…);
  • test.beforeEach(…);
  • test.afterEach(…);
  • test.afterEach.always(…);
  • test(…);

This rule is fixable as long as no other code is between the hooks that need to be reordered.

Fail

const test = require('ava');

test.after(t => {
	doFoo();
});

test.before(t => {
	doFoo();
});

test('foo', t => {
	t.true(true);
});
const test = require('ava');

test('foo', t => {
	t.true(true);
});

test.before(t => {
	doFoo();
});

Pass

const test = require('ava');

test.before(t => {
	doFoo();
});

test.after(t => {
	doFoo();
});

test.after.always(t => {
	doFoo();
});

test.beforeEach(t => {
	doFoo();
});

test.afterEach(t => {
	doFoo();
});

test.afterEach.always(t => {
	doFoo();
});

test('foo', t => {
	t.true(true);
});