Skip to content

Commit 605b351

Browse files
author
Robert Jackson
committed
Fix this.subject replacement for moduleFor + integration: true.
1 parent 919da92 commit 605b351

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

__testfixtures__/ember-qunit-codemod/subject.input.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,13 @@ test('can use service', function (assert) {
8181
moduleFor('service:foo');
8282

8383
test('does not require more than one argument', function(assert) {
84-
let suject = this.subject();
84+
let subject = this.subject();
85+
});
86+
87+
moduleFor('service:foo', {
88+
integration: true
89+
});
90+
91+
test('can use subject in moduleFor + integration: true', function(assert) {
92+
let subject = this.subject();
8593
});

__testfixtures__/ember-qunit-codemod/subject.output.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ module('service:foo', function(hooks) {
8787
setupTest(hooks);
8888

8989
test('does not require more than one argument', function(assert) {
90-
let subject = this.owner.factoryFor('component:foo-bar').create();
90+
let subject = this.owner.lookup('service:foo');
91+
});
92+
});
93+
94+
module('service:foo', function(hooks) {
95+
setupTest(hooks);
96+
97+
test('can use subject in moduleFor + integration: true', function(assert) {
98+
let subject = this.owner.lookup('service:foo');
9199
});
92100
});

ember-qunit-codemod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ module.exports = function(file, api, options) {
110110
if (lastArgument.type === 'ObjectExpression') {
111111
options = calleeArguments.pop();
112112
}
113-
subject = moduleName = calleeArguments[1] || calleeArguments[0];
113+
moduleName = calleeArguments[1] || calleeArguments[0];
114+
subject = calleeArguments[0];
114115

115116
let setupIdentifier = 'setupTest';
116117
if (options) {
@@ -119,13 +120,12 @@ module.exports = function(file, api, options) {
119120
if (calleeName === `moduleForComponent`) {
120121
if (hasIntegration) {
121122
setupIdentifier = 'setupRenderingTest';
123+
subject = null;
122124
} else {
123125
subject = j.literal(`component:${calleeArguments[0].value}`);
124126
}
125127
} else if (calleeName === 'moduleForModel') {
126128
subject = j.literal(`model:${calleeArguments[0].value}`);
127-
} else if (!hasIntegration) {
128-
subject = calleeArguments[0];
129129
}
130130

131131
hasCustomSubject = options.properties.some(p => p.key.name === 'subject');

0 commit comments

Comments
 (0)