OLD | NEW |
(Empty) | |
| 1 <sky> |
| 2 <import src="/sky/tests//resources/chai.sky" /> |
| 3 <import src="/sky/tests/resources/mocha.sky" /> |
| 4 <import src="/sky/tests/resources/test-element.sky" as="TestElement" /> |
| 5 |
| 6 <div id="sandbox"></div> |
| 7 |
| 8 <script> |
| 9 describe("SkyElement templates", function() { |
| 10 var element; |
| 11 var sandbox = document.getElementById("sandbox"); |
| 12 |
| 13 beforeEach(function() { |
| 14 element = new TestElement(); |
| 15 }); |
| 16 afterEach(function() { |
| 17 element.remove(); |
| 18 }); |
| 19 |
| 20 it("should stamp when the element is inserted", function() { |
| 21 assert.isNull(element.shadowRoot); |
| 22 sandbox.appendChild(element); |
| 23 assert.instanceOf(element.shadowRoot, ShadowRoot); |
| 24 assert.ok(element.shadowRoot.getElementById("inside")); |
| 25 }); |
| 26 |
| 27 it("should connect data binding", function(done) { |
| 28 sandbox.appendChild(element); |
| 29 var inside = element.shadowRoot.getElementById("inside"); |
| 30 Promise.resolve().then(function() { |
| 31 assert.equal(inside.textContent, 10); |
| 32 assert.equal(inside.attr, 10); |
| 33 element.value = 20; |
| 34 }).then(function() { |
| 35 assert.equal(inside.textContent, 20); |
| 36 assert.equal(inside.attr, 20); |
| 37 done(); |
| 38 }).catch(function(e) { |
| 39 done(e); |
| 40 }); |
| 41 }); |
| 42 |
| 43 it("should connect event handlers", function() { |
| 44 sandbox.appendChild(element); |
| 45 var inside = element.shadowRoot.getElementById("inside"); |
| 46 inside.dispatchEvent(new CustomEvent("wrong-event")); |
| 47 assert.isNull(element.lastEvent); |
| 48 var event = new CustomEvent("test-event"); |
| 49 inside.dispatchEvent(event); |
| 50 assert.equal(element.lastEvent, event); |
| 51 }); |
| 52 }); |
| 53 </script> |
| 54 </sky> |
OLD | NEW |