Skip to content

Commit dff635a

Browse files
Fix issue with no-deprecated-router-transition-methods throwing errors outside of class usage (#2046)
* Failing tets for no deprecatde router transition methods * minimize test * fix lint:fix eh
1 parent 6b0b522 commit dff635a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/rules/no-deprecated-router-transition-methods.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ module.exports = {
187187

188188
const currentClass = classStack.peek();
189189

190+
if (!currentClass) {
191+
return;
192+
}
193+
190194
if (types.isThisExpression(node.object) && types.isIdentifier(node.property)) {
191195
// Routes should not call transitionTo or replaceWith
192196
const propertyName = node.property.name;

tests/lib/rules/no-deprecated-router-transition-methods.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,30 @@ ruleTester.run('no-deprecated-router-transition-methods', rule, {
358358
@computed.reads('model.actors') actors;
359359
}`,
360360
},
361+
362+
// Does not error when `this` is from a test context
363+
{
364+
filename: 'tests/application/output-demos-test.ts',
365+
code: `
366+
import Controller from '@ember/controller';
367+
import { visit } from '@ember/test-helpers';
368+
import { module, test } from 'qunit';
369+
import { setupApplicationTest } from 'ember-qunit';
370+
371+
module('Output > Demos', function (hooks) {
372+
setupApplicationTest(hooks);
373+
374+
module('The output frame renders every demo', function () {
375+
test('example', async function (assert) {
376+
class FakeController extends Controller {}
377+
this.owner.register('controller:edit', FakeController);
378+
await visit('/edit');
379+
});
380+
});
381+
});
382+
383+
`,
384+
},
361385
],
362386
invalid: [
363387
// Route Uses RouterService.transitionTo with different service injection types

0 commit comments

Comments
 (0)