Closed Bug 1022558 Opened 6 years ago Closed 2 years ago

Tested files should be required in beforeAll hooks

Categories

(Firefox OS Graveyard :: Gaia::System, defect)

defect
Not set

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: stas, Unassigned)

References

Details

This surfaced in bug 1000895.  In particular, see bug 1000895 comment 15.  There are inconsistencies in how tests initialize System components with regards to localization:

 a) Some System app tests require the tested JS file before they assign navigator.mozL10n = MockL10n, i.e. when navigator.mozL10n is undefined (it's not a platform API but is provided by shared/js/l10n.js)

 b) Even if mozL10n is already defined, MockL10n.once calls the init method at the time when the tested file was required;  this results in errors in cases when the init method needed access to DOM.

I find the following pattern from https://github.com/mozilla-b2g/gaia/blob/089d170f986d2916e3551935c74bf4c865f45cfd/apps/system/test/unit/activity_window_test.js quite elegant:

  setup(function(done) {
    stubById = this.sinon.stub(document, 'getElementById');
    stubById.returns(document.createElement('div'));
    // ...
    requireApp('system/js/activity_window.js', done);
  });

activity_window.js is required in a before[All] hook and it can safely access the DOM thanks to the stub.  I'd like other test files to use this pattern, which will make fixing bug 1004973 easier.
Firefox OS is not being worked on
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.