Skip to content

Latest commit

 

History

History
78 lines (58 loc) · 1.5 KB

no-ember-testing-in-module-scope.md

File metadata and controls

78 lines (58 loc) · 1.5 KB

ember/no-ember-testing-in-module-scope

💼 This rule is enabled in the ✅ recommended config.

Ember.testing is not allowed in modules scope.

Since [email protected] / [email protected], Ember.testing is only set to true while a test is executing instead of all the time. Also, Ember.testing is a getter/setter in Ember and destructuring will only read its value at the time of destructuring.

emberjs/ember-test-helpers#227

Examples

Examples of incorrect code for this rule:

import Component from '@ember/component';

export default Component.extend({
  init(...args) {
    this._super(...args);
    this.isTesting = Ember.testing;
  }
});
import Ember from 'ember';
import Component from '@ember/component';

export default Component.extend({
  isTesting: Ember.testing
});
import Ember from 'ember';

const IS_TESTING = Ember.testing;
import Ember from 'ember';

const { testing } = Ember;

Examples of correct code for this rule:

import Ember from 'ember';
import Component from '@ember/component';

export default Component.extend({
  someMethod() {
    if (Ember.testing) {
      doSomething();
    } else {
      doSomethingElse();
    }
  }
});
import Ember from 'ember';
import Service from '@ember/service';

export default Service.extend({
  foo() {
    _bar(Ember.testing ? 0 : 400);
  }
});