Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
raycohen opened this issue Apr 4, 2021 · 1 comment
Closed

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

raycohen opened this issue Apr 4, 2021 · 1 comment
Assignees
Labels
Component: Core For module, test, hooks, and reporters. Type: Enhancement New idea or feature request.
Milestone

Comments

@raycohen
Copy link
Member

raycohen commented Apr 4, 2021

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?

@Krinkle Krinkle added Component: Core For module, test, hooks, and reporters. Type: Enhancement New idea or feature request. labels Apr 4, 2021
@Krinkle
Copy link
Member

Krinkle commented Apr 4, 2021

Yeah, I agree we could flag this automatically. Basically if hooks are called on during the top-level executeNow() phase of a module, we would throw an error if it is not for the current inner-most module. This would mean it would also throw if you for some reason intentionally named them differently and accessed it directly:

module('outer', hooks => {
  test('one', );

  module('inner a', gizmos => {
    gizmos.beforeEach();
    hooks.beforeEach(); // will throw Error
    test('two', );
  });
});

I'd welcome this change in a PR, to land for QUnit 3. Preferably to first as a warning to land in QUnit 2.x, to aid in migration (or fixing of mistakes) prior to the upgrade.

@Krinkle Krinkle added this to the 3.0 release milestone Apr 4, 2021
raycohen added a commit to raycohen/qunit that referenced this issue Apr 5, 2021
raycohen added a commit to raycohen/qunit that referenced this issue Apr 10, 2021
Krinkle pushed a commit that referenced this issue Apr 10, 2021
This will become an error in QUnit 3.

Ref #1576.
Closes #1586.
Krinkle pushed a commit to Krinkle/qunit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Krinkle pushed a commit to Krinkle/qunit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Krinkle pushed a commit to Krinkle/qunit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Krinkle pushed a commit to raycohen/qunit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Closes qunitjs#1578
Krinkle pushed a commit to raycohen/qunit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Closes qunitjs#1578
Krinkle added a commit that referenced this issue Jun 7, 2024
Change deprecation warning into an error.

Ref #1576
Closes #1578

Co-authored-by: Ray Cohen <raycohen@gmail.com>
Krinkle pushed a commit to raycohen/qunit that referenced this issue Jun 8, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Closes qunitjs#1578
Krinkle pushed a commit to raycohen/qunit that referenced this issue Jun 8, 2024
Change deprecation warning into an error.

Ref qunitjs#1576
Closes qunitjs#1578
Krinkle pushed a commit that referenced this issue Jun 8, 2024
Change deprecation warning into an error.

Ref #1576
Closes #1578
@Krinkle Krinkle closed this as completed Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core For module, test, hooks, and reporters. Type: Enhancement New idea or feature request.
Development

No branches or pull requests

2 participants