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

Unable to test Ember.onError after upgrading #250

Closed
workmanw opened this issue Dec 1, 2016 · 5 comments
Closed

Unable to test Ember.onError after upgrading #250

workmanw opened this issue Dec 1, 2016 · 5 comments

Comments

@workmanw
Copy link

workmanw commented Dec 1, 2016

I'm in the process of upgrading to ember 2.10. One of the packages upgraded was ember-cli-qunit which in turn upgrades ember-qunit to 2.0. One problem that I'm faced with is that I am now unable to acceptance test my application's error handling (which is oddly complex and important to test).

The problem is that ember-qunit now providers their own test adapter (See: ember-qunit#234). And the test-loader bundled with ember-cli-qunit just imports it, instanitaties it and set's it as global (See: ember-cli-qunit#134).

Before this upgrade I would just do the following:

let useEmberOnError = false;
Ember.Test.QUnitAdapter.reopen({
  exception(error) {
    if (useEmberOnError) {
      Ember.onerror(error);
      return;
    }

    this._super(...arguments);
  }
});

But now I'm no longer able to monkey patch this. I think I could probably replace the Ember.Test.adapter instance with my own, but this feels brittle. I'm curious what you guys think the "right solution" might be to acceptance test application error handling.

@rwjblue
Copy link
Member

rwjblue commented Dec 1, 2016

I think the best way to do this is:

// tests/qunit-adapter.js
import { QUnitAdapter } from 'ember-qunit';

let useEmberOnError = false;
export default QUnitAdapter.extend({
  exception(error) {
    if (useEmberOnError) {
      Ember.onerror(error);
      return;
    }

    this._super(...arguments);
  }
})
// tests/test-helper.js

/* existing contents */

import QUnitAdapter from './qunit-adapter';
Ember.Test.adapter = QUnitAdapter.create();

@rwjblue
Copy link
Member

rwjblue commented Dec 1, 2016

FWIW, I think ^ was also the best way to do this before ember-qunit@2 too.

@workmanw
Copy link
Author

workmanw commented Dec 1, 2016

@rwjblue Okay, yea. I think I just needed to reorient my thinking on this. Overriding the adapter in this way feels natural to me. The globals just make things seem wonky sometimes. I think the one catch is you have to be careful when you set the global adapter so that it's done after the test-loader sets it.

It seems like import { QUnitAdapter } from 'ember-qunit'; is probably here to stay for a while? Meaning my extending and replacing of it isn't likely to cause a feature regression.

@workmanw workmanw closed this as completed Dec 1, 2016
@kbullaughey
Copy link

Now with the start() method for starting tests, which was added in ember-cli-qunit@4, I needed to invoke it as follows for this strategy to work:

start({setupTestAdapter: false});

@thisFunction
Copy link

start({setupTestAdapter: false});

Thanks, @kbullaughey! This worked for me when testing backend error responses.

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

No branches or pull requests

4 participants