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

Share 'before' hook test environment with child module #1328

Closed
ming-codes opened this issue Oct 29, 2018 · 3 comments · Fixed by #1762
Closed

Share 'before' hook test environment with child module #1328

ming-codes opened this issue Oct 29, 2018 · 3 comments · Fixed by #1762
Assignees
Labels
Milestone

Comments

@ming-codes
Copy link

Tell us about your runtime:

  • QUnit version: 2.6.2
  • What environment are you running QUnit in? (e.g., browser, Node): browser
  • How are you running QUnit? (e.g., script, testem, Grunt): ember-qunit

What are you trying to do?

module('parent', function(hooks) {
  hooks.before(function() {
    this.hello = 'world';
  });

  test('outer', function(assert) {
    assert.equal(this.hello, 'world'); // pass
  });

  module('child', function() {
    test('inner', function(assert) {
      assert.equal(this.hello, 'world'); // fails
    });
  });
});

What did you expect to happen?

Expecting nested child modules to share test environment with parent module.

What actually happened?

Nested child module have it's own test environment object.

@gibson042
Copy link
Member

This is a practical issue that would be resolved by implementing #869.

@Krinkle Krinkle added Category: API Type: Enhancement New idea or feature request. labels Dec 22, 2018
@Krinkle Krinkle changed the title before hook test environment not shared with child module Share 'before' hook test environment with child module Dec 27, 2018
@Krinkle Krinkle added this to the 3.0 milestone Aug 30, 2020
@Krinkle
Copy link
Member

Krinkle commented Aug 30, 2020

I've confirmed beforeEach is shared as expected, and that before still is not.

https://codepen.io/Krinkle/pen/JjXJgoz

Changing this is imho considered a breaking change, but a good one to make in the 3.0 release.

@Krinkle
Copy link
Member

Krinkle commented Nov 7, 2020

TODO: Figure out how we can help users prepare for this ahead of the QUnit 3.0 release so that any difference in behaviour can be smoothened out and warned for.

@Krinkle Krinkle removed this from the 3.0 release milestone Nov 7, 2020
@Krinkle Krinkle mentioned this issue Nov 7, 2020
14 tasks
@Krinkle Krinkle added this to the 3.0 release milestone Nov 11, 2020
raycohen added a commit to raycohen/qunit that referenced this issue Mar 4, 2021
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
raycohen added a commit to raycohen/qunit that referenced this issue Mar 5, 2021
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
raycohen added a commit to raycohen/qunit that referenced this issue Mar 20, 2021
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
raycohen added a commit to raycohen/qunit that referenced this issue Jun 9, 2024
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
raycohen added a commit to raycohen/qunit that referenced this issue Jun 14, 2024
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
raycohen added a commit to raycohen/qunit that referenced this issue Jun 21, 2024
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Fixes qunitjs#1328.
Ref qunitjs#869.
Krinkle pushed a commit to raycohen/qunit that referenced this issue Jun 23, 2024
The before and after hooks run once per module as long as there is at least one
test in the module. Using environment inheritance allows us to use the module
context in those hooks, which allows reading the expected changes to the
context from a before hook inside nested modules.

Once before hooks have run, create a flattened deep copy of the module
testEnvironment and assign that to test testEnvironment. At this point nothing
should use test.testEnvironment until the before hooks have run.

Fixes qunitjs#1328.
Ref qunitjs#869.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment