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

Ember.testing set inconsistently #297

Closed
RobbieTheWagner opened this issue Nov 14, 2017 · 4 comments
Closed

Ember.testing set inconsistently #297

RobbieTheWagner opened this issue Nov 14, 2017 · 4 comments
Labels

Comments

@RobbieTheWagner
Copy link
Member

RobbieTheWagner commented Nov 14, 2017

After speaking with and debugging code with @rwjblue we seem to have discovered that a regression was introduced by emberjs/ember-test-helpers#227 in which Ember.testing is now no longer consistently set to true when testing.

If you use a vanilla qunit module, rather than moduleFor from ember-qunit Ember.testing is false most of the time. It is inconsistent though and depends on the timing of when the test is run.

@rwjblue
Copy link
Member

rwjblue commented Nov 14, 2017

Awesome, thank you for reporting.

I think the right solution is to add a QUnit.testStart / QUnit.testDone to ensure Ember.testing is true during all types of tests. The alternative is to manually "wrap" the raw QUnit.test function, but I find that very distasteful (and we have been working very very hard to remove these sorts of charades)...

@bobisjan
Copy link
Contributor

Hi @rwjblue,

thanks for working on this, after updating I've found one case in our test suite which fails (QUnit.testStart is called little bit later).

// app/utils/debounce.js
import Ember from 'ember';

const debounce = Ember.testing ? 0 : 500;

export default debounce;
// tests/unit/utils/debounce-test.js
import debounce from 'app/utils/debounce';
import { module, test } from 'qunit';

module('Unit | Utility | debounce');

test('it works', function(assert) {
  assert.equal(debounce, 0);
});

Not sure if it's a valid usage of Ember.testing, but it worked before 🙇‍♂️.

@rwjblue
Copy link
Member

rwjblue commented Dec 18, 2017

Sorry this is biting you, but checking Ember.testing in module scope is definitely a thing to be avoided. The intention of Ember.testing is to tell you that an actual test is underway, but in your example that is not the case.

It seems like what you are actually trying to do is ensure that whenever in the testing environment that you use a very short debounce value. A more semantic alternative for your use case would be something like:

import config from `../config/environment’;

const debounce = config.environment === ‘test’ ? 0 : 500;

export default debounce;

Hope that helps!

@bobisjan
Copy link
Contributor

@rwjblue, thanks for clarification! Your solution works like a charm ☺️.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants