Skip to content

Commit

Permalink
Fix issue with no-deprecated-router-transition-methods throwing err…
Browse files Browse the repository at this point in the history
…ors outside of class usage (#2046)

* Failing tets for no deprecatde router transition methods

* minimize test

* fix

lint:fix

eh
  • Loading branch information
NullVoxPopuli committed Dec 31, 2023
1 parent 6b0b522 commit dff635a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-deprecated-router-transition-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ module.exports = {

const currentClass = classStack.peek();

if (!currentClass) {
return;
}

if (types.isThisExpression(node.object) && types.isIdentifier(node.property)) {
// Routes should not call transitionTo or replaceWith
const propertyName = node.property.name;
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/rules/no-deprecated-router-transition-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@ ruleTester.run('no-deprecated-router-transition-methods', rule, {
@computed.reads('model.actors') actors;
}`,
},

// Does not error when `this` is from a test context
{
filename: 'tests/application/output-demos-test.ts',
code: `
import Controller from '@ember/controller';
import { visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
module('Output > Demos', function (hooks) {
setupApplicationTest(hooks);
module('The output frame renders every demo', function () {
test('example', async function (assert) {
class FakeController extends Controller {}
this.owner.register('controller:edit', FakeController);
await visit('/edit');
});
});
});
`,
},
],
invalid: [
// Route Uses RouterService.transitionTo with different service injection types
Expand Down

0 comments on commit dff635a

Please sign in to comment.