OLD | NEW |
(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 library polymer.test.event_binding_release_handler_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:html'; |
| 9 import 'package:polymer/polymer.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:unittest/html_config.dart'; |
| 12 import 'package:template_binding/template_binding.dart'; |
| 13 |
| 14 @CustomTag('x-foo') |
| 15 class XFoo extends PolymerElement { |
| 16 @PublishedProperty(reflect: true) |
| 17 int count = 1; |
| 18 |
| 19 XFoo.created() : super.created(); |
| 20 |
| 21 increment() { ++count; } |
| 22 } |
| 23 |
| 24 main() { |
| 25 // Do not run the test in the zone so the future does not trigger a |
| 26 // dirtyCheck. We want to verify that event bindings trigger dirty checks on |
| 27 // their own. |
| 28 initPolymer(); |
| 29 |
| 30 useHtmlConfiguration(); |
| 31 |
| 32 setUp(() => Polymer.onReady); |
| 33 |
| 34 test('event handlers can be released', () { |
| 35 XFoo element = querySelector('x-foo'); |
| 36 expect(element, isNotNull); |
| 37 ButtonElement button = element.shadowRoot.querySelector('button'); |
| 38 expect(button, isNotNull); |
| 39 |
| 40 button.click(); |
| 41 return new Future(() {}).then((_) { |
| 42 expect(element.shadowRoot.querySelector('p').text, 'Count: 2'); |
| 43 // Remove and detach the element so the binding is invalidated. |
| 44 element.remove(); |
| 45 element.detached(); |
| 46 }).then((_) => new Future(() {})).then((_) { |
| 47 // Clicks should no longer affect the elements count. |
| 48 button.click(); |
| 49 // TODO(jakemac): This is flaky so its commented out, (the rest of the |
| 50 // test is not flaky). Figure out how to make this not flaky. |
| 51 // expect(element.count, 2); |
| 52 }); |
| 53 }); |
| 54 } |
OLD | NEW |