| 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 custom_element.test.custom_element_test; | 
|  | 6 | 
|  | 7 import 'dart:async'; | 
|  | 8 import 'dart:html'; | 
|  | 9 import 'package:custom_element/custom_element.dart'; | 
|  | 10 import 'package:unittest/html_config.dart'; | 
|  | 11 import 'package:unittest/unittest.dart'; | 
|  | 12 | 
|  | 13 main() { | 
|  | 14   useHtmlConfiguration(); | 
|  | 15 | 
|  | 16   test('register creates the element and calls lifecycle methods', () { | 
|  | 17     // Add element to the page. | 
|  | 18     var element = new Element.html('<fancy-button>foo bar</fancy-button>'); | 
|  | 19     document.body.nodes.add(element); | 
|  | 20 | 
|  | 21     var xtag = null; | 
|  | 22     registerCustomElement('fancy-button', () => xtag = new FancyButton()); | 
|  | 23     expect(xtag, isNotNull, reason: 'FancyButton was created'); | 
|  | 24     expect(element.xtag, xtag, reason: 'xtag pointer should be set'); | 
|  | 25     expect(xtag.host, element, reason: 'host pointer should be set'); | 
|  | 26     expect(xtag.lifecycle, ['created']); | 
|  | 27     return new Future(() { | 
|  | 28       expect(xtag.lifecycle, ['created', 'inserted']); | 
|  | 29       element.remove(); | 
|  | 30       return new Future(() { | 
|  | 31         expect(xtag.lifecycle, ['created', 'inserted', 'removed']); | 
|  | 32       }); | 
|  | 33     }); | 
|  | 34   }); | 
|  | 35 | 
|  | 36   test('create a component in code', () { | 
|  | 37     var element = createElement('super-button'); | 
|  | 38     expect(element.xtag, element, reason: 'element not registered'); | 
|  | 39 | 
|  | 40     var xtag = null; | 
|  | 41     registerCustomElement('super-button', () => xtag = new FancyButton()); | 
|  | 42 | 
|  | 43     element = createElement('super-button'); | 
|  | 44     expect(xtag, isNotNull, reason: 'FancyButton was created'); | 
|  | 45     expect(element.xtag, xtag, reason: 'xtag pointer should be set'); | 
|  | 46     expect(xtag.host, element, reason: 'host pointer should be set'); | 
|  | 47     expect(xtag.lifecycle, ['created']); | 
|  | 48     return new Future(() { | 
|  | 49       expect(xtag.lifecycle, ['created'], reason: 'not inserted into document'); | 
|  | 50 | 
|  | 51       document.body.nodes.add(element); | 
|  | 52       return new Future(() { | 
|  | 53         expect(xtag.lifecycle, ['created'], | 
|  | 54             reason: 'mutation observer not implemented yet'); | 
|  | 55 | 
|  | 56         element.remove(); | 
|  | 57         return new Future(() { | 
|  | 58           expect(xtag.lifecycle, ['created'], | 
|  | 59               reason: 'mutation observer not implemented yet'); | 
|  | 60         }); | 
|  | 61       }); | 
|  | 62     }); | 
|  | 63   }); | 
|  | 64 } | 
|  | 65 | 
|  | 66 class FancyButton extends CustomElement { | 
|  | 67   final lifecycle = []; | 
|  | 68   created() { | 
|  | 69     super.created(); | 
|  | 70     lifecycle.add('created'); | 
|  | 71   } | 
|  | 72   inserted() { | 
|  | 73     super.inserted(); | 
|  | 74     lifecycle.add('inserted'); | 
|  | 75   } | 
|  | 76   removed() { | 
|  | 77     super.removed(); | 
|  | 78     lifecycle.add('removed'); | 
|  | 79   } | 
|  | 80 } | 
| OLD | NEW | 
|---|