Skip to content

Commit 182b937

Browse files
author
Robert Jackson
committed
Ensure this.subject is processed in beforeEach.
1 parent ac41bfd commit 182b937

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ moduleFor('service:foo', {
6565
test('can use custom subject', function(assert) {
6666
let subject = this.subject();
6767
});
68+
69+
moduleFor('service:foo', 'Unit | Service | Foo', {
70+
unit: true,
71+
72+
beforeEach() {
73+
this.service = this.subject();
74+
}
75+
});
76+
77+
test('can use service', function (assert) {
78+
this.servicer.something();
79+
});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,15 @@ module('service:foo', function(hooks) {
7070
let subject = this.subject();
7171
});
7272
});
73+
74+
module('Unit | Service | Foo', function(hooks) {
75+
setupTest(hooks);
76+
77+
hooks.beforeEach(function() {
78+
this.service = this.owner.lookup('service:foo');
79+
});
80+
81+
test('can use service', function (assert) {
82+
this.servicer.something();
83+
});
84+
});

ember-qunit-codemod.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ module.exports = function(file, api, options) {
188188

189189
// preserve any comments that were present
190190
lifecycleStatement.comments = property.comments;
191-
processExpressionForRenderingTest(lifecycleStatement);
192191

193192
callback.body.body.push(lifecycleStatement);
194193
} else if (isMethod(property)) {
@@ -227,8 +226,10 @@ module.exports = function(file, api, options) {
227226
}
228227
});
229228

230-
if (customMethodBeforeEachExpression) {
231-
processExpressionForRenderingTest(customMethodBeforeEachExpression);
229+
if (setupType === 'setupRenderingTest') {
230+
processExpressionForRenderingTest(callback);
231+
} else {
232+
processSubject(callback, subject);
232233
}
233234
}
234235

0 commit comments

Comments
 (0)