test(upgrade): change flaky test to not be affected by other tests (#28617)

It seems that in some cases (especially on CI), global state is not
cleaned up properly causing a specific test to fail.
See #28045 and #28181 for more context.

This PR restores the global state for the affected test. This partly
defeat the purpose of the test, but is better than having flakes on CI.

Fixes #28614

PR Close #28617
This commit is contained in:
George Kalpakas 2019-02-08 13:51:51 +02:00 committed by Miško Hevery
parent 0e4705aec3
commit 1ff3699d99
1 changed files with 8 additions and 13 deletions

View File

@ -28,20 +28,15 @@ import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTemp
expect(injector).toBe(mockInjector);
});
it('should throw if the injector value has not been set yet', () => {
let injector: IInjectorService|null = null;
it('should throw if the injector value is not set', () => {
// Ensure the injector is not set. This shouldn't be necessary, but on CI there seems to be
// some race condition with previous tests not being cleaned up properly.
// Related:
// - https://github.com/angular/angular/pull/28045
// - https://github.com/angular/angular/pull/28181
setTempInjectorRef(null as any);
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)}`);
expect(injectorFactory).toThrowError();
});
it('should unset the injector after the first call (to prevent memory leaks)', () => {