Skip to content

Commit 45b7c15

Browse files
committed
Replace this.register with this.owner.register
1 parent bb67fd8 commit 45b7c15

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('service:foo', 'Unit | Service | Foo', {
4+
beforeEach() {
5+
this.register('service:thingy', thingy);
6+
}
7+
});
8+
9+
test('it happens', function() {
10+
this.register('service:thingy', thingy);
11+
});
12+
13+
moduleFor('service:bar', 'Unit | Service | Bar');
14+
15+
test('it happens again?', function() {
16+
this.register('service:thingy', thingy);
17+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Service | Foo', function(hooks) {
5+
setupTest(hooks);
6+
7+
hooks.beforeEach(function() {
8+
this.owner.register('service:thingy', thingy);
9+
});
10+
11+
test('it happens', function() {
12+
this.owner.register('service:thingy', thingy);
13+
});
14+
});
15+
16+
module('Unit | Service | Bar', function(hooks) {
17+
setupTest(hooks);
18+
19+
test('it happens again?', function() {
20+
this.owner.register('service:thingy', thingy);
21+
});
22+
});

ember-qunit-codemod.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ function updateLookupCalls(j, root) {
256256
});
257257
}
258258

259+
function updateRegisterCalls(j, root) {
260+
return root
261+
.find(j.MemberExpression, {
262+
object: { type: 'ThisExpression' },
263+
property: { name: 'register' },
264+
})
265+
.forEach(path => {
266+
let thisDotOwner = j.memberExpression(j.thisExpression(), j.identifier('owner'));
267+
path.replace(j.memberExpression(thisDotOwner, path.value.property));
268+
});
269+
}
270+
259271
module.exports = function(file, api, options) {
260272
const j = api.jscodeshift;
261273

@@ -272,6 +284,7 @@ module.exports = function(file, api, options) {
272284
updateToNewEmberQUnitImports(j, root);
273285
updateModuleForToNestedModule(j, root);
274286
updateLookupCalls(j, root);
287+
updateRegisterCalls(j, root);
275288

276289
return root.toSource(printOptions);
277290
};

0 commit comments

Comments
 (0)