Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.49 KB

no-hooks-from-ancestor-modules.md

File metadata and controls

53 lines (38 loc) · 1.49 KB

Disallow the use of hooks from ancestor modules (qunit/no-hooks-from-ancestor-modules)

💼 This rule is enabled in the ✅ recommended config.

When a QUnit module is used with a nested callback, the callback provides a hooks object as its first argument. This allows calling hooks.beforeEach and hooks.afterEach within that callback's body.

More deeply nested module uses should use their own callback's provided hooks argument and not one from an ancestor module.

Rule Details

The following patterns are considered warnings:

QUnit.module("outer module", function(hooks) {
    QUnit.module("inner module", function() {
        hooks.beforeEach(function() {});
    });
});

QUnit.module("outer module", function(outerHooks) {
    QUnit.module("inner module", function(innerHooks) {
        outerHooks.beforeEach(function() {});
    });
});

The following patterns are not warnings:

QUnit.module("example module", function(hooks) {
    hooks.beforeEach(function() {});
});

QUnit.module("outer module", function() {
    QUnit.module("inner module", function(hooks) {
        hooks.beforeEach(function() {});
    });
});

When Not To Use It

This rule may be safely disabled if you are working in a legacy codebase that will not migrate to QUnit 2.0.

Further Reading