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
This commit is contained in:
JoostK 2019-11-16 23:49:12 +01:00 committed by Alex Rickabaugh
parent e2cba6ed7d
commit 19a6c158d2
1 changed files with 6 additions and 22 deletions

View File

@ -379,28 +379,12 @@ 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');
});
expect(decorators[0].name).toBe('Inject');
expect(decorators[0].import !.from).toBe('@angular/core');
expect(decorators[0].import !.name).toBe('Inject');
});
});