Skip to content

Error when a hook is invoked inside the wrong module #1576

@raycohen

Description

@raycohen

When a user forgets to provide the hooks param in a module callback, they may unintentionally install a hook on a different module than is visually indicated, eg:

module('outer', function (hooks) {
  test('one', ...);

  module('inner a', function () {
    hooks.beforeEach(...); // will run before all three tests even though visually nested in "inner a"
    test('two', ...);
  });

  module('inner b', function () {
    test('three', ...);
  });
});

There is a lint rule for this, but I think it would make sense for QUnit to throw an error when this occurs. Is there any reason a user would want to do this intentionally?

Metadata

Metadata

Assignees

Labels

Component: CoreFor module, test, hooks, and reporters.Type: EnhancementNew idea or feature request.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions