Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: pkg/polymer_expressions/test/polymer_expressions_test.dart

Issue 26619002: Log exceptions caught in polymer expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:html'; // To indicate that this is an html test.
7
8 import 'package:logging/logging.dart';
9 import 'package:observe/observe.dart';
10 import 'package:observe/src/microtask.dart';
11 import 'package:polymer_expressions/polymer_expressions.dart';
12 import 'package:unittest/unittest.dart';
13 import 'package:unittest/html_config.dart';
14
15
16 main() {
17 useHtmlConfiguration();
18 group('binding', () {
19 var stop = null;
20 var messages = [];
21 var model;
22 setUp(() {
23 stop = Logger.root.onRecord.listen((r) => messages.add(r));
24 model = new Foo();
25 });
26
27 tearDown(() {
28 stop.cancel();
29 stop = null;
30 messages = [];
31 });
32
33 observeTest('should update binding when data changes', () {
34 var binding = new PolymerExpressions()
35 .getBinding(model, 'name', null, null);
36 expect(binding.value, isNull);
37 model.name = "hi";
38 performMicrotaskCheckpoint();
39 expect(binding.value, 'hi');
40 expect(messages.length, 0);
41 });
42
43 observeTest('should log getter exceptions', () {
44 var binding = new PolymerExpressions()
45 .getBinding(model, 'readException', null, null);
46 expect(binding.value, isNull);
47 expect(messages.length, 1);
48 expect(messages[0].message,
49 "Error evaluating expression 'readException': exception (read)");
50 });
51
52 observeTest('should log setter exceptions', () {
53 var binding = new PolymerExpressions()
54 .getBinding(model, 'writeException', null, null);
55 expect(binding.value, '');
56 binding.value = 'hi';
57 performMicrotaskCheckpoint();
58 expect(messages.length, 1);
59 expect(messages[0].message,
60 "Error evaluating expression 'writeException': exception hi");
61 });
62 });
63 }
64
65 class Foo extends Object with ChangeNotifierMixin {
66 String _name;
67 String get name => _name;
68 void set name(String n) {
69 _name = notifyPropertyChange(const Symbol('name'), _name, n);
70 }
71
72 String get readException => throw "exception (read)";
73 void set readException(String value) => throw "exception $value";
74
75 String get writeException => '';
76 void set writeException(String value) => throw "exception $value";
77 }
78
79
80 /**
81 * This is a special kind of unit [test], that supports
82 * calling [performMicrotaskCheckpoint] during the test to pump events
83 * that original from observable objects.
84 */
85 observeTest(name, testCase) => test(name, wrapMicrotask(testCase));
86
87 /** The [solo_test] version of [observeTest]. */
88 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698