diff --git a/tests/lib/rules/no-deprecated-router-transition-methods.js b/tests/lib/rules/no-deprecated-router-transition-methods.js index ff51b524be..4dc44ae3f3 100644 --- a/tests/lib/rules/no-deprecated-router-transition-methods.js +++ b/tests/lib/rules/no-deprecated-router-transition-methods.js @@ -873,5 +873,59 @@ import Controller from '@ember/controller'; }, ], }, + + // Multiple classes in a single file + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @action + foo() { + this.transitionTo('login'); + } + } + + export class AnotherRoute extends Route { + @action + foo() { + this.transitionTo('login'); + } + }`, + output: ` + import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @service('router') router; +@action + foo() { + this.router.transitionTo('login'); + } + } + + export class AnotherRoute extends Route { + @service('router') router; +@action + foo() { + this.router.transitionTo('login'); + } + }`, + errors: [ + { + messageId: 'main', + data: { methodUsed: 'transitionTo', desiredMethod: 'transitionTo', moduleType: 'Route' }, + type: 'MemberExpression', + }, + { + messageId: 'main', + data: { methodUsed: 'transitionTo', desiredMethod: 'transitionTo', moduleType: 'Route' }, + type: 'MemberExpression', + }, + ], + }, ], }); diff --git a/tests/lib/rules/no-implicit-injections.js b/tests/lib/rules/no-implicit-injections.js index bf85d8e3d4..86669af119 100644 --- a/tests/lib/rules/no-implicit-injections.js +++ b/tests/lib/rules/no-implicit-injections.js @@ -879,5 +879,51 @@ actions: { { messageId: 'main', data: { serviceName: 'flash-messages' }, type: 'MemberExpression' }, ], }, + + // Multiple classes in a single file + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @action + foo() { + this.store.find('test'); + } + } + + export class AnotherRoute extends Route { + @action + foo() { + this.store.find('test'); + } + }`, + output: ` + import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @service('store') store; +@action + foo() { + this.store.find('test'); + } + } + + export class AnotherRoute extends Route { + @service('store') store; +@action + foo() { + this.store.find('test'); + } + }`, + errors: [ + { messageId: 'main', data: { serviceName: 'store' }, type: 'MemberExpression' }, + { messageId: 'main', data: { serviceName: 'store' }, type: 'MemberExpression' }, + ], + }, ], });