qunit icon indicating copy to clipboard operation
qunit copied to clipboard

Share 'before' hook test environment with child module

Open ming-codes opened this issue 7 years ago • 3 comments

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.

ming-codes avatar Oct 29 '18 22:10 ming-codes

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

gibson042 avatar Oct 30 '18 01:10 gibson042

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 avatar Aug 30 '20 23:08 Krinkle

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 avatar Nov 07 '20 20:11 Krinkle