From 6c5c97b2f92a0ea4f0aab2afc0dc8c958db47487 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 11 Oct 2018 17:44:59 +0300 Subject: [PATCH] refactor(upgrade): use a constant for `$exceptionHandler` (#26217) PR Close #26217 --- packages/upgrade/src/common/constants.ts | 1 + packages/upgrade/test/dynamic/upgrade_spec.ts | 5 ++-- .../integration/downgrade_component_spec.ts | 29 +++++++------------ .../integration/upgrade_component_spec.ts | 12 ++++---- packages/upgrade/test/static/test_helpers.ts | 4 +-- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/packages/upgrade/src/common/constants.ts b/packages/upgrade/src/common/constants.ts index 207d3867be..99a57f808a 100644 --- a/packages/upgrade/src/common/constants.ts +++ b/packages/upgrade/src/common/constants.ts @@ -9,6 +9,7 @@ export const $COMPILE = '$compile'; export const $CONTROLLER = '$controller'; export const $DELEGATE = '$delegate'; +export const $EXCEPTION_HANDLER = '$exceptionHandler'; export const $HTTP_BACKEND = '$httpBackend'; export const $INJECTOR = '$injector'; export const $INTERVAL = '$interval'; diff --git a/packages/upgrade/test/dynamic/upgrade_spec.ts b/packages/upgrade/test/dynamic/upgrade_spec.ts index 2544ed3dec..84f52cd90b 100644 --- a/packages/upgrade/test/dynamic/upgrade_spec.ts +++ b/packages/upgrade/test/dynamic/upgrade_spec.ts @@ -11,6 +11,7 @@ import {async, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import * as angular from '@angular/upgrade/src/common/angular1'; +import {$EXCEPTION_HANDLER} from '@angular/upgrade/src/common/constants'; import {UpgradeAdapter, UpgradeAdapterRef} from '@angular/upgrade/src/dynamic/upgrade_adapter'; import {$apply, $digest, html, multiTrim, withEachNg1Version} from './test_helpers'; @@ -318,7 +319,7 @@ withEachNg1Version(() => { it('should bind properties, events', async(() => { const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module)); const ng1Module = - angular.module('ng1', []).value('$exceptionHandler', (err: any) => { throw err; }); + angular.module('ng1', []).value($EXCEPTION_HANDLER, (err: any) => { throw err; }); ng1Module.run(($rootScope: any) => { $rootScope.name = 'world'; @@ -2904,7 +2905,7 @@ withEachNg1Version(() => { // Define `ng1Module` const ng1Module = angular.module('ng1Module', []) - .value('$exceptionHandler', (error: Error) => errorMessage = error.message) + .value($EXCEPTION_HANDLER, (error: Error) => errorMessage = error.message) .component('ng1', ng1Component) .directive('ng2', adapter.downgradeNg2Component(Ng2Component)); diff --git a/packages/upgrade/test/static/integration/downgrade_component_spec.ts b/packages/upgrade/test/static/integration/downgrade_component_spec.ts index 3e9284bf4b..3ca52b98d3 100644 --- a/packages/upgrade/test/static/integration/downgrade_component_spec.ts +++ b/packages/upgrade/test/static/integration/downgrade_component_spec.ts @@ -22,18 +22,15 @@ withEachNg1Version(() => { afterEach(() => destroyPlatform()); it('should bind properties, events', async(() => { - const ng1Module = - angular.module('ng1', []).value('$exceptionHandler', (err: any) => { - throw err; - }).run(($rootScope: angular.IScope) => { - $rootScope['name'] = 'world'; - $rootScope['dataA'] = 'A'; - $rootScope['dataB'] = 'B'; - $rootScope['modelA'] = 'initModelA'; - $rootScope['modelB'] = 'initModelB'; - $rootScope['eventA'] = '?'; - $rootScope['eventB'] = '?'; - }); + const ng1Module = angular.module('ng1', []).run(($rootScope: angular.IScope) => { + $rootScope['name'] = 'world'; + $rootScope['dataA'] = 'A'; + $rootScope['dataB'] = 'B'; + $rootScope['modelA'] = 'initModelA'; + $rootScope['modelB'] = 'initModelB'; + $rootScope['eventA'] = '?'; + $rootScope['eventB'] = '?'; + }); @Component({ selector: 'ng2', @@ -149,12 +146,8 @@ withEachNg1Version(() => { })); it('should bind properties to onpush components', async(() => { - const ng1Module = - angular.module('ng1', []).value('$exceptionHandler', (err: any) => { - throw err; - }).run(($rootScope: angular.IScope) => { - $rootScope['dataB'] = 'B'; - }); + const ng1Module = angular.module('ng1', []).run( + ($rootScope: angular.IScope) => { $rootScope['dataB'] = 'B'; }); @Component({ selector: 'ng2', diff --git a/packages/upgrade/test/static/integration/upgrade_component_spec.ts b/packages/upgrade/test/static/integration/upgrade_component_spec.ts index fe20a9b00f..d318b2f3f7 100644 --- a/packages/upgrade/test/static/integration/upgrade_component_spec.ts +++ b/packages/upgrade/test/static/integration/upgrade_component_spec.ts @@ -12,7 +12,7 @@ import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static'; import * as angular from '@angular/upgrade/static/src/common/angular1'; -import {$SCOPE} from '@angular/upgrade/static/src/common/constants'; +import {$EXCEPTION_HANDLER, $SCOPE} from '@angular/upgrade/static/src/common/constants'; import {$digest, bootstrap, html, multiTrim, withEachNg1Version} from '../test_helpers'; @@ -1777,7 +1777,7 @@ withEachNg1Version(() => { } // Define `ng1Module` - const mockExceptionHandler = jasmine.createSpy('$exceptionHandler'); + const mockExceptionHandler = jasmine.createSpy($EXCEPTION_HANDLER); const ng1Module = angular.module('ng1Module', []) .component('ng1A', ng1ComponentA) @@ -1786,7 +1786,7 @@ withEachNg1Version(() => { .directive('ng2A', downgradeComponent({component: Ng2ComponentA})) .directive('ng2B', downgradeComponent({component: Ng2ComponentB})) .directive('ng2C', downgradeComponent({component: Ng2ComponentC})) - .value('$exceptionHandler', mockExceptionHandler); + .value($EXCEPTION_HANDLER, mockExceptionHandler); // Define `Ng2Module` @NgModule({ @@ -1849,11 +1849,11 @@ withEachNg1Version(() => { } // Define `ng1Module` - const mockExceptionHandler = jasmine.createSpy('$exceptionHandler'); + const mockExceptionHandler = jasmine.createSpy($EXCEPTION_HANDLER); const ng1Module = angular.module('ng1Module', []) .component('ng1', ng1Component) .directive('ng2', downgradeComponent({component: Ng2Component})) - .value('$exceptionHandler', mockExceptionHandler); + .value($EXCEPTION_HANDLER, mockExceptionHandler); // Define `Ng2Module` @NgModule({ @@ -2502,7 +2502,7 @@ withEachNg1Version(() => { // Define `ng1Module` const ng1Module = angular.module('ng1Module', []) - .value('$exceptionHandler', (error: Error) => errorMessage = error.message) + .value($EXCEPTION_HANDLER, (error: Error) => errorMessage = error.message) .component('ng1', ng1Component) .directive('ng2', downgradeComponent({component: Ng2Component})); diff --git a/packages/upgrade/test/static/test_helpers.ts b/packages/upgrade/test/static/test_helpers.ts index cb94b3bb52..8f32c1f43e 100644 --- a/packages/upgrade/test/static/test_helpers.ts +++ b/packages/upgrade/test/static/test_helpers.ts @@ -9,7 +9,7 @@ import {NgZone, PlatformRef, Type} from '@angular/core'; import {UpgradeModule} from '@angular/upgrade/static'; import * as angular from '@angular/upgrade/static/src/common/angular1'; -import {$ROOT_SCOPE} from '@angular/upgrade/static/src/common/constants'; +import {$EXCEPTION_HANDLER, $ROOT_SCOPE} from '@angular/upgrade/static/src/common/constants'; import {createWithEachNg1VersionFn} from '../common/test_helpers'; export * from '../common/test_helpers'; @@ -22,7 +22,7 @@ export function bootstrap( const ngZone = ref.injector.get(NgZone); const upgrade = ref.injector.get(UpgradeModule); const failHardModule: any = ($provide: angular.IProvideService) => { - $provide.value('$exceptionHandler', (err: any) => { throw err; }); + $provide.value($EXCEPTION_HANDLER, (err: any) => { throw err; }); }; // The `bootstrap()` helper is used for convenience in tests, so that we don't have to inject