Skip to content

Commit 6f2f981

Browse files
authored
Merge pull request #26 from rwjblue/prevent-errors-with-single-arg
Fix various issues with `subject` detection.
2 parents 9c81b0f + 605b351 commit 6f2f981

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ moduleFor('service:foo', 'Unit | Service | Foo', {
7777
test('can use service', function (assert) {
7878
this.service.something();
7979
});
80+
81+
moduleFor('service:foo');
82+
83+
test('does not require more than one argument', function(assert) {
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();
93+
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ module('Unit | Service | Foo', function(hooks) {
8282
this.service.something();
8383
});
8484
});
85+
86+
module('service:foo', function(hooks) {
87+
setupTest(hooks);
88+
89+
test('does not require more than one argument', function(assert) {
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');
99+
});
100+
});

ember-qunit-codemod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = function(file, api, options) {
111111
options = calleeArguments.pop();
112112
}
113113
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)