Skip to content

Commit

Permalink
Merge pull request #1189 from bmish/service-injection-test-add
Browse files Browse the repository at this point in the history
Add a few test cases for service injection detection
  • Loading branch information
bmish authored May 9, 2021
2 parents f481ce9 + ed113f4 commit 19c77d0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/lib/utils/ember-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,31 @@ describe('isInjectedServiceProp', () => {
@service currentUser;
}
`);
const node = context.ast.body[1].body.body[0];
expect(emberUtils.isInjectedServiceProp(node, undefined, 'service')).toBeTruthy();
});

it("should check if it's an injected service prop when service is from another object", () => {
const context = new FauxContext(`
import {inject as service} from '@ember/service';
class MyController extends Controller {
@foo.service currentUser;
}
`);
const node = context.ast.body[1].body.body[0];
expect(emberUtils.isInjectedServiceProp(node, undefined, 'service')).toBeFalsy();
});

it("should check if it's an injected service prop when another function from service", () => {
const context = new FauxContext(`
import {inject as service} from '@ember/service';
class MyController extends Controller {
@service.foo currentUser;
}
`);
const importName = context.ast.body[0].specifiers[0].local.name;
const node = context.ast.body[1].body.body[0];
expect(emberUtils.isInjectedServiceProp(node, undefined, importName)).toBeTruthy();
expect(emberUtils.isInjectedServiceProp(node, undefined, importName)).toBeFalsy();
});

it("should check if it's an injected service prop when using decorator", () => {
Expand Down

0 comments on commit 19c77d0

Please sign in to comment.