refactor(upgrade): use a constant for `$exceptionHandler` (#26217)
PR Close #26217
This commit is contained in:
parent
099d1a67a0
commit
6c5c97b2f9
|
@ -9,6 +9,7 @@
|
||||||
export const $COMPILE = '$compile';
|
export const $COMPILE = '$compile';
|
||||||
export const $CONTROLLER = '$controller';
|
export const $CONTROLLER = '$controller';
|
||||||
export const $DELEGATE = '$delegate';
|
export const $DELEGATE = '$delegate';
|
||||||
|
export const $EXCEPTION_HANDLER = '$exceptionHandler';
|
||||||
export const $HTTP_BACKEND = '$httpBackend';
|
export const $HTTP_BACKEND = '$httpBackend';
|
||||||
export const $INJECTOR = '$injector';
|
export const $INJECTOR = '$injector';
|
||||||
export const $INTERVAL = '$interval';
|
export const $INTERVAL = '$interval';
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {async, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import * as angular from '@angular/upgrade/src/common/angular1';
|
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 {UpgradeAdapter, UpgradeAdapterRef} from '@angular/upgrade/src/dynamic/upgrade_adapter';
|
||||||
|
|
||||||
import {$apply, $digest, html, multiTrim, withEachNg1Version} from './test_helpers';
|
import {$apply, $digest, html, multiTrim, withEachNg1Version} from './test_helpers';
|
||||||
|
@ -318,7 +319,7 @@ withEachNg1Version(() => {
|
||||||
it('should bind properties, events', async(() => {
|
it('should bind properties, events', async(() => {
|
||||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||||
const ng1Module =
|
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) => {
|
ng1Module.run(($rootScope: any) => {
|
||||||
$rootScope.name = 'world';
|
$rootScope.name = 'world';
|
||||||
|
@ -2904,7 +2905,7 @@ withEachNg1Version(() => {
|
||||||
// Define `ng1Module`
|
// Define `ng1Module`
|
||||||
const ng1Module =
|
const ng1Module =
|
||||||
angular.module('ng1Module', [])
|
angular.module('ng1Module', [])
|
||||||
.value('$exceptionHandler', (error: Error) => errorMessage = error.message)
|
.value($EXCEPTION_HANDLER, (error: Error) => errorMessage = error.message)
|
||||||
.component('ng1', ng1Component)
|
.component('ng1', ng1Component)
|
||||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||||
|
|
||||||
|
|
|
@ -22,18 +22,15 @@ withEachNg1Version(() => {
|
||||||
afterEach(() => destroyPlatform());
|
afterEach(() => destroyPlatform());
|
||||||
|
|
||||||
it('should bind properties, events', async(() => {
|
it('should bind properties, events', async(() => {
|
||||||
const ng1Module =
|
const ng1Module = angular.module('ng1', []).run(($rootScope: angular.IScope) => {
|
||||||
angular.module('ng1', []).value('$exceptionHandler', (err: any) => {
|
$rootScope['name'] = 'world';
|
||||||
throw err;
|
$rootScope['dataA'] = 'A';
|
||||||
}).run(($rootScope: angular.IScope) => {
|
$rootScope['dataB'] = 'B';
|
||||||
$rootScope['name'] = 'world';
|
$rootScope['modelA'] = 'initModelA';
|
||||||
$rootScope['dataA'] = 'A';
|
$rootScope['modelB'] = 'initModelB';
|
||||||
$rootScope['dataB'] = 'B';
|
$rootScope['eventA'] = '?';
|
||||||
$rootScope['modelA'] = 'initModelA';
|
$rootScope['eventB'] = '?';
|
||||||
$rootScope['modelB'] = 'initModelB';
|
});
|
||||||
$rootScope['eventA'] = '?';
|
|
||||||
$rootScope['eventB'] = '?';
|
|
||||||
});
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ng2',
|
selector: 'ng2',
|
||||||
|
@ -149,12 +146,8 @@ withEachNg1Version(() => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should bind properties to onpush components', async(() => {
|
it('should bind properties to onpush components', async(() => {
|
||||||
const ng1Module =
|
const ng1Module = angular.module('ng1', []).run(
|
||||||
angular.module('ng1', []).value('$exceptionHandler', (err: any) => {
|
($rootScope: angular.IScope) => { $rootScope['dataB'] = 'B'; });
|
||||||
throw err;
|
|
||||||
}).run(($rootScope: angular.IScope) => {
|
|
||||||
$rootScope['dataB'] = 'B';
|
|
||||||
});
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ng2',
|
selector: 'ng2',
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
||||||
import * as angular from '@angular/upgrade/static/src/common/angular1';
|
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';
|
import {$digest, bootstrap, html, multiTrim, withEachNg1Version} from '../test_helpers';
|
||||||
|
|
||||||
|
@ -1777,7 +1777,7 @@ withEachNg1Version(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define `ng1Module`
|
// Define `ng1Module`
|
||||||
const mockExceptionHandler = jasmine.createSpy('$exceptionHandler');
|
const mockExceptionHandler = jasmine.createSpy($EXCEPTION_HANDLER);
|
||||||
const ng1Module =
|
const ng1Module =
|
||||||
angular.module('ng1Module', [])
|
angular.module('ng1Module', [])
|
||||||
.component('ng1A', ng1ComponentA)
|
.component('ng1A', ng1ComponentA)
|
||||||
|
@ -1786,7 +1786,7 @@ withEachNg1Version(() => {
|
||||||
.directive('ng2A', downgradeComponent({component: Ng2ComponentA}))
|
.directive('ng2A', downgradeComponent({component: Ng2ComponentA}))
|
||||||
.directive('ng2B', downgradeComponent({component: Ng2ComponentB}))
|
.directive('ng2B', downgradeComponent({component: Ng2ComponentB}))
|
||||||
.directive('ng2C', downgradeComponent({component: Ng2ComponentC}))
|
.directive('ng2C', downgradeComponent({component: Ng2ComponentC}))
|
||||||
.value('$exceptionHandler', mockExceptionHandler);
|
.value($EXCEPTION_HANDLER, mockExceptionHandler);
|
||||||
|
|
||||||
// Define `Ng2Module`
|
// Define `Ng2Module`
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -1849,11 +1849,11 @@ withEachNg1Version(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define `ng1Module`
|
// Define `ng1Module`
|
||||||
const mockExceptionHandler = jasmine.createSpy('$exceptionHandler');
|
const mockExceptionHandler = jasmine.createSpy($EXCEPTION_HANDLER);
|
||||||
const ng1Module = angular.module('ng1Module', [])
|
const ng1Module = angular.module('ng1Module', [])
|
||||||
.component('ng1', ng1Component)
|
.component('ng1', ng1Component)
|
||||||
.directive('ng2', downgradeComponent({component: Ng2Component}))
|
.directive('ng2', downgradeComponent({component: Ng2Component}))
|
||||||
.value('$exceptionHandler', mockExceptionHandler);
|
.value($EXCEPTION_HANDLER, mockExceptionHandler);
|
||||||
|
|
||||||
// Define `Ng2Module`
|
// Define `Ng2Module`
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -2502,7 +2502,7 @@ withEachNg1Version(() => {
|
||||||
// Define `ng1Module`
|
// Define `ng1Module`
|
||||||
const ng1Module =
|
const ng1Module =
|
||||||
angular.module('ng1Module', [])
|
angular.module('ng1Module', [])
|
||||||
.value('$exceptionHandler', (error: Error) => errorMessage = error.message)
|
.value($EXCEPTION_HANDLER, (error: Error) => errorMessage = error.message)
|
||||||
.component('ng1', ng1Component)
|
.component('ng1', ng1Component)
|
||||||
.directive('ng2', downgradeComponent({component: Ng2Component}));
|
.directive('ng2', downgradeComponent({component: Ng2Component}));
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {NgZone, PlatformRef, Type} from '@angular/core';
|
import {NgZone, PlatformRef, Type} from '@angular/core';
|
||||||
import {UpgradeModule} from '@angular/upgrade/static';
|
import {UpgradeModule} from '@angular/upgrade/static';
|
||||||
import * as angular from '@angular/upgrade/static/src/common/angular1';
|
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';
|
import {createWithEachNg1VersionFn} from '../common/test_helpers';
|
||||||
export * from '../common/test_helpers';
|
export * from '../common/test_helpers';
|
||||||
|
@ -22,7 +22,7 @@ export function bootstrap(
|
||||||
const ngZone = ref.injector.get<NgZone>(NgZone);
|
const ngZone = ref.injector.get<NgZone>(NgZone);
|
||||||
const upgrade = ref.injector.get(UpgradeModule);
|
const upgrade = ref.injector.get(UpgradeModule);
|
||||||
const failHardModule: any = ($provide: angular.IProvideService) => {
|
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
|
// The `bootstrap()` helper is used for convenience in tests, so that we don't have to inject
|
||||||
|
|
Loading…
Reference in New Issue