Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit e8bc580

Browse files
pavelgjmhevery
authored andcommitted
fix(scope): correctly setup NgZone onError handler with ExceptionHandler
Close #621
1 parent 99eb022 commit e8bc580

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/core/scope.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ class RootScope extends Scope {
388388
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context))
389389
{
390390
_zone.onTurnDone = apply;
391+
_zone.onError = (e, s, ls) => _exceptionHandler(e, s);
391392
}
392393

393394
RootScope get rootScope => this;

test/core/scope_spec.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ library scope2_spec;
33
import '../_specs.dart';
44
import 'package:angular/change_detection/change_detection.dart' hide ExceptionHandler;
55
import 'package:angular/change_detection/dirty_checking_change_detector.dart';
6+
import 'dart:async';
67
import 'dart:math';
78

89
main() => describe('scope', () {
@@ -1285,6 +1286,40 @@ main() => describe('scope', () {
12851286
});
12861287
});
12871288
});
1289+
1290+
describe('exceptionHander', () {
1291+
it('should call ExceptionHandler on zone errors', () {
1292+
module((Module module) {
1293+
module.type(ExceptionHandler, implementedBy: LoggingExceptionHandler);
1294+
});
1295+
async((inject((RootScope rootScope, NgZone zone, ExceptionHandler e) {
1296+
zone.run(() {
1297+
scheduleMicrotask(() => throw 'my error');
1298+
});
1299+
var errors = (e as LoggingExceptionHandler).errors;
1300+
expect(errors.length).toEqual(1);
1301+
expect(errors.first.error).toEqual('my error');
1302+
})));
1303+
});
1304+
1305+
it('should call ExceptionHandler on digest errors', () {
1306+
module((Module module) {
1307+
module.type(ExceptionHandler, implementedBy: LoggingExceptionHandler);
1308+
});
1309+
async((inject((RootScope rootScope, NgZone zone, ExceptionHandler e) {
1310+
rootScope.context['badOne'] = () => new Map();
1311+
rootScope.watch('badOne()', (_, __) => null);
1312+
1313+
try {
1314+
zone.run(() => null);
1315+
} catch(_) {}
1316+
1317+
var errors = (e as LoggingExceptionHandler).errors;
1318+
expect(errors.length).toEqual(1);
1319+
expect(errors.first.error, startsWith('Model did not stabilize'));
1320+
})));
1321+
});
1322+
});
12881323
});
12891324

12901325
@NgFilter(name: 'multiply')

0 commit comments

Comments
 (0)