From 19a6c158d211d9b5a3be23696e596b2da5ccb472 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 16 Nov 2019 23:49:12 +0100 Subject: [PATCH] test(ngcc): avoid using spy in `Esm2015ReflectionHost` test (#33878) A testcase that was using a spy has shown itself to be brittle, and its assertions can easily be moved into a related test. PR Close #33878 --- .../host/esm2015_host_import_helper_spec.ts | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts index a978c13ff6..da7b484a92 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts @@ -379,29 +379,13 @@ runInEachFileSystem(() => { 'TemplateRef', null, ]); + + const decorators = parameters ![2].decorators !; + expect(decorators.length).toEqual(1); + expect(decorators[0].name).toBe('Inject'); + expect(decorators[0].import !.from).toBe('@angular/core'); + expect(decorators[0].import !.name).toBe('Inject'); }); - - describe('(returned parameters `decorators`)', () => { - it('should use `getImportOfIdentifier()` to retrieve import info', () => { - const mockImportInfo = {} as Import; - const spy = spyOn(Esm2015ReflectionHost.prototype, 'getImportOfIdentifier') - .and.returnValue(mockImportInfo); - - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); - const parameters = host.getConstructorParameters(classNode); - const decorators = parameters ![2].decorators !; - - expect(decorators.length).toEqual(1); - expect(decorators[0].import).toBe(mockImportInfo); - - const typeIdentifier = spy.calls.mostRecent().args[0] as ts.Identifier; - expect(typeIdentifier.text).toBe('Inject'); - }); - }); }); describe('getDeclarationOfIdentifier', () => {