From 1ff3699d9900931815f859305c7478c0a965b253 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 8 Feb 2019 13:51:51 +0200 Subject: [PATCH] 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 --- .../test/static/angular1_providers_spec.ts | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/upgrade/test/static/angular1_providers_spec.ts b/packages/upgrade/test/static/angular1_providers_spec.ts index 0662d36c72..6b44b87143 100644 --- a/packages/upgrade/test/static/angular1_providers_spec.ts +++ b/packages/upgrade/test/static/angular1_providers_spec.ts @@ -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)', () => {