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

Transform this.subject in non-rendering tests #9

Closed
rwjblue opened this issue Oct 20, 2017 · 0 comments
Closed

Transform this.subject in non-rendering tests #9

rwjblue opened this issue Oct 20, 2017 · 0 comments
Assignees

Comments

@rwjblue
Copy link
Member

rwjblue commented Oct 20, 2017

In order to allow the codemod to leave applications in a working state, we will need to provide a path away from using this.subject(). This transformation is discussed in emberjs/rfcs#232 here.

We should transform the following for singletons (e.g. everything other than model and component):

import { moduleFor, test } from 'ember-qunit';

moduleFor('service:flash', 'Unit | Service | Flash', {
  unit: true
});

test('should allow messages to be queued', function (assert) {  
  let subject = this.subject();
  // ...snip...
});

Into this:

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | Flash', function(hooks) {
  setupTest(hooks);
  
  test('should allow messages to be queued', function (assert) {
    let subject = this.owner.lookup('service:flash');
    // ...snip...
  });
});

And for non-singleton's we would do:

import { moduleFor, test } from 'ember-qunit';

moduleFor('model:foo', 'Unit | Model | Foo', {
  unit: true
});

test('should allow messages to be queued', function (assert) {  
  let subject = this.subject();
  // ...snip...
});

Into:

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Model | Foo', function(hooks) {
  setupTest(hooks);
  
  test('should allow messages to be queued', function (assert) {
    let subject = this.owner.factoryFor('model:foo').create();
    // ...snip...
  });
});
@rwjblue rwjblue self-assigned this Oct 20, 2017
cibernox added a commit to cibernox/ember-qunit-codemod that referenced this issue Oct 20, 2017
rwjblue pushed a commit to cibernox/ember-qunit-codemod that referenced this issue Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant