Skip to content
Permalink
Browse files

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
  • Loading branch information
JoostK authored and alxhub committed Nov 16, 2019
1 parent e47638e commit 80cd7d7a4000f3bd9e3070b0aaaeb9b22453443f
Showing with 6 additions and 22 deletions.
  1. +6 −22 packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts
@@ -379,29 +379,13 @@ runInEachFileSystem(() => {
'TemplateRef',
null,
]);
});

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');
});
});
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('getDeclarationOfIdentifier', () => {

0 comments on commit 80cd7d7

Please sign in to comment.
You can’t perform that action at this time.