OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <sky> |
| 3 <import src="../resources/mocha.sky" /> |
| 4 <import src="../resources/chai.sky" /> |
| 5 <style> |
| 6 div { font-size: 5px; } |
| 7 .font-10 { font-size: 10px; } |
| 8 .font-12 { font-size: 12px; } |
| 9 .font-24 { font-size: 24px; } |
| 10 </style> |
| 11 <div id="sandbox"></div> |
| 12 <script> |
| 13 describe("Class list", function() { |
| 14 var sandbox = document.getElementById("sandbox"); |
| 15 var target; |
| 16 |
| 17 beforeEach(function() { |
| 18 target = document.createElement("div"); |
| 19 sandbox.appendChild(target); |
| 20 }); |
| 21 |
| 22 afterEach(function() { |
| 23 target.remove(); |
| 24 }); |
| 25 |
| 26 it("should add multiple classes", function() { |
| 27 target.classList.add("first", "second", "third"); |
| 28 assert.equal(target.classList.toString(), "first second third"); |
| 29 }); |
| 30 |
| 31 it("should add classes in order", function() { |
| 32 target.classList.add("first"); |
| 33 target.classList.add("second"); |
| 34 assert.equal(target.classList.toString(), "first second"); |
| 35 }); |
| 36 |
| 37 it("should remove classes", function() { |
| 38 target.classList.add("first"); |
| 39 target.classList.add("second"); |
| 40 target.classList.add("third"); |
| 41 target.classList.remove("second"); |
| 42 assert.equal(target.classList.toString(), "first third"); |
| 43 }); |
| 44 |
| 45 it("should remove multiple classes", function() { |
| 46 target.classList.add("first", "second", "third"); |
| 47 target.classList.remove("first", "third"); |
| 48 assert.equal(target.classList.toString(), "second"); |
| 49 }); |
| 50 |
| 51 it("should check for classes", function() { |
| 52 target.classList.add("first", "second", "third"); |
| 53 assert.isTrue(target.classList.contains("first")); |
| 54 assert.isTrue(target.classList.contains("second")); |
| 55 assert.isTrue(target.classList.contains("third")); |
| 56 target.classList.remove("second"); |
| 57 assert.isTrue(target.classList.contains("first")); |
| 58 assert.isFalse(target.classList.contains("second")); |
| 59 assert.isTrue(target.classList.contains("third")); |
| 60 }); |
| 61 |
| 62 it("should get classes by index", function() { |
| 63 target.classList.add("first", "second", "third"); |
| 64 assert.equal(target.classList[0], "first"); |
| 65 assert.equal(target.classList[1], "second"); |
| 66 assert.equal(target.classList[2], "third"); |
| 67 assert.equal(target.classList.item(0), "first"); |
| 68 assert.equal(target.classList.item(1), "second"); |
| 69 assert.equal(target.classList.item(2), "third"); |
| 70 }); |
| 71 |
| 72 it("should toggle classes", function() { |
| 73 target.classList.add("first", "second"); |
| 74 assert.isFalse(target.classList.toggle("first")); |
| 75 assert.equal(target.classList.toString(), "second"); |
| 76 assert.isTrue(target.classList.toggle("first")); |
| 77 assert.equal(target.classList.toString(), "second first"); |
| 78 assert.isTrue(target.classList.toggle("second", true)); |
| 79 assert.equal(target.classList.toString(), "second first"); |
| 80 assert.isTrue(target.classList.toggle("second", true)); |
| 81 assert.isFalse(target.classList.toggle("second", false)); |
| 82 assert.isFalse(target.classList.toggle("second", false)); |
| 83 assert.equal(target.classList.toString(), "first"); |
| 84 }); |
| 85 |
| 86 it("should dynamically update style", function() { |
| 87 assert.equal(getComputedStyle(target).fontSize, "5px"); |
| 88 target.classList.add("font-10"); |
| 89 target.classList.add("font-12"); |
| 90 assert.equal(getComputedStyle(target).fontSize, "12px"); |
| 91 target.classList.add("font-24"); |
| 92 assert.equal(getComputedStyle(target).fontSize, "24px"); |
| 93 target.classList.remove("font-12"); |
| 94 assert.equal(getComputedStyle(target).fontSize, "24px"); |
| 95 target.classList.remove("font-24"); |
| 96 assert.equal(getComputedStyle(target).fontSize, "10px"); |
| 97 target.classList.remove("font-10"); |
| 98 assert.equal(getComputedStyle(target).fontSize, "5px"); |
| 99 }); |
| 100 }); |
| 101 </script> |
| 102 </sky> |
OLD | NEW |