Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 1.38 KB

hooks-order.md

File metadata and controls

85 lines (61 loc) · 1.38 KB

Enforce test hook ordering (ava/hooks-order)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

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);
});