| Index: pkg/polymer_expressions/test/polymer_expressions_test.dart
|
| diff --git a/pkg/polymer_expressions/test/polymer_expressions_test.dart b/pkg/polymer_expressions/test/polymer_expressions_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..76db0f9833b9f6bcc71ae9d395075cfc17cf5f6d
|
| --- /dev/null
|
| +++ b/pkg/polymer_expressions/test/polymer_expressions_test.dart
|
| @@ -0,0 +1,88 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'dart:async';
|
| +import 'dart:html'; // To indicate that this is an html test.
|
| +
|
| +import 'package:logging/logging.dart';
|
| +import 'package:observe/observe.dart';
|
| +import 'package:observe/src/microtask.dart';
|
| +import 'package:polymer_expressions/polymer_expressions.dart';
|
| +import 'package:unittest/unittest.dart';
|
| +import 'package:unittest/html_config.dart';
|
| +
|
| +
|
| +main() {
|
| + useHtmlConfiguration();
|
| + group('binding', () {
|
| + var stop = null;
|
| + var messages = [];
|
| + var model;
|
| + setUp(() {
|
| + stop = Logger.root.onRecord.listen((r) => messages.add(r));
|
| + model = new Foo();
|
| + });
|
| +
|
| + tearDown(() {
|
| + stop.cancel();
|
| + stop = null;
|
| + messages = [];
|
| + });
|
| +
|
| + observeTest('should update binding when data changes', () {
|
| + var binding = new PolymerExpressions()
|
| + .getBinding(model, 'name', null, null);
|
| + expect(binding.value, isNull);
|
| + model.name = "hi";
|
| + performMicrotaskCheckpoint();
|
| + expect(binding.value, 'hi');
|
| + expect(messages.length, 0);
|
| + });
|
| +
|
| + observeTest('should log getter exceptions', () {
|
| + var binding = new PolymerExpressions()
|
| + .getBinding(model, 'readException', null, null);
|
| + expect(binding.value, isNull);
|
| + expect(messages.length, 1);
|
| + expect(messages[0].message,
|
| + "Error evaluating expression 'readException': exception (read)");
|
| + });
|
| +
|
| + observeTest('should log setter exceptions', () {
|
| + var binding = new PolymerExpressions()
|
| + .getBinding(model, 'writeException', null, null);
|
| + expect(binding.value, '');
|
| + binding.value = 'hi';
|
| + performMicrotaskCheckpoint();
|
| + expect(messages.length, 1);
|
| + expect(messages[0].message,
|
| + "Error evaluating expression 'writeException': exception hi");
|
| + });
|
| + });
|
| +}
|
| +
|
| +class Foo extends Object with ChangeNotifierMixin {
|
| + String _name;
|
| + String get name => _name;
|
| + void set name(String n) {
|
| + _name = notifyPropertyChange(const Symbol('name'), _name, n);
|
| + }
|
| +
|
| + String get readException => throw "exception (read)";
|
| + void set readException(String value) => throw "exception $value";
|
| +
|
| + String get writeException => '';
|
| + void set writeException(String value) => throw "exception $value";
|
| +}
|
| +
|
| +
|
| +/**
|
| + * This is a special kind of unit [test], that supports
|
| + * calling [performMicrotaskCheckpoint] during the test to pump events
|
| + * that original from observable objects.
|
| + */
|
| +observeTest(name, testCase) => test(name, wrapMicrotask(testCase));
|
| +
|
| +/** The [solo_test] version of [observeTest]. */
|
| +solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase));
|
|
|