Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class RootScope extends Scope {
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context))
{
_zone.onTurnDone = apply;
_zone.onError = (e, s, ls) => _exceptionHandler(e, s);
}

RootScope get rootScope => this;
Expand Down
35 changes: 35 additions & 0 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ library scope2_spec;
import '../_specs.dart';
import 'package:angular/change_detection/change_detection.dart' hide ExceptionHandler;
import 'package:angular/change_detection/dirty_checking_change_detector.dart';
import 'dart:async';
import 'dart:math';

main() => describe('scope', () {
Expand Down Expand Up @@ -1285,6 +1286,40 @@ main() => describe('scope', () {
});
});
});

describe('exceptionHander', () {
it('should call ExceptionHandler on zone errors', () {
module((Module module) {
module.type(ExceptionHandler, implementedBy: LoggingExceptionHandler);
});
async((inject((RootScope rootScope, NgZone zone, ExceptionHandler e) {
zone.run(() {
scheduleMicrotask(() => throw 'my error');
});
var errors = (e as LoggingExceptionHandler).errors;
expect(errors.length).toEqual(1);
expect(errors.first.error).toEqual('my error');
})));
});

it('should call ExceptionHandler on digest errors', () {
module((Module module) {
module.type(ExceptionHandler, implementedBy: LoggingExceptionHandler);
});
async((inject((RootScope rootScope, NgZone zone, ExceptionHandler e) {
rootScope.context['badOne'] = () => new Map();
rootScope.watch('badOne()', (_, __) => null);

try {
zone.run(() => null);
} catch(_) {}

var errors = (e as LoggingExceptionHandler).errors;
expect(errors.length).toEqual(1);
expect(errors.first.error, startsWith('Model did not stabilize'));
})));
});
});
});

@NgFilter(name: 'multiply')
Expand Down