test(upgrade): log more info to help debug CI flakes (#28045)

Related Jira issue: FW-939

PR Close #28045
This commit is contained in:
George Kalpakas
2019-01-10 17:18:05 +02:00
committed by Andrew Kushnir
parent f05c5f82c8
commit 5c680d4aa8
2 changed files with 18 additions and 7 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Ng1Token} from '@angular/upgrade/static/src/common/angular1';
import {IInjectorService, Ng1Token} from '@angular/upgrade/static/src/common/angular1';
import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTempInjectorRef} from '@angular/upgrade/static/src/static/angular1_providers';
{
@ -22,19 +22,30 @@ import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTemp
describe('injectorFactory', () => {
it('should return the injector value that was previously set', () => {
const mockInjector = {get: () => {}, has: () => false};
const mockInjector = {get: () => undefined, has: () => false};
setTempInjectorRef(mockInjector);
const injector = injectorFactory();
expect(injector).toBe(mockInjector);
});
it('should throw if the injector value has not been set yet', () => {
const mockInjector = {get: () => {}, has: () => false};
expect(injectorFactory).toThrowError();
let injector: IInjectorService|null = null;
try {
injector = injectorFactory();
} catch {
// Throwing an error is the expected behavior.
return;
}
// Normally, we should never get here (but sometimes we do on CI).
// Log some info to help debug the issue.
console.error(`Unexpected injector (${typeof injector}):`, injector);
fail(`Expected no injector, but got: ${jasmine.pp(injector)}`);
});
it('should unset the injector after the first call (to prevent memory leaks)', () => {
const mockInjector = {get: () => {}, has: () => false};
const mockInjector = {get: () => undefined, has: () => false};
setTempInjectorRef(mockInjector);
injectorFactory();
expect(injectorFactory).toThrowError(); // ...because it has been unset