Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
michael@0 | 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
michael@0 | 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
michael@0 | 4 | <head> |
michael@0 | 5 | <title>script.aculo.us Unit test file</title> |
michael@0 | 6 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
michael@0 | 7 | <script src="../../lib/prototype.js" type="text/javascript"></script> |
michael@0 | 8 | <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
michael@0 | 9 | <script src="../../src/unittest.js" type="text/javascript"></script> |
michael@0 | 10 | <link rel="stylesheet" href="../test.css" type="text/css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <h1>script.aculo.us Unit test file</h1> |
michael@0 | 14 | |
michael@0 | 15 | <!-- Log output --> |
michael@0 | 16 | <div id="testlog"> </div> |
michael@0 | 17 | |
michael@0 | 18 | <div id="d">initial</div> |
michael@0 | 19 | |
michael@0 | 20 | <!-- Tests follow --> |
michael@0 | 21 | <script type="text/javascript" language="javascript" charset="utf-8"> |
michael@0 | 22 | // <![CDATA[ |
michael@0 | 23 | var moo = 0; |
michael@0 | 24 | |
michael@0 | 25 | var assertMethods = []; |
michael@0 | 26 | for(method in Test.Unit.Assertions.prototype) { |
michael@0 | 27 | if(/^assert/.test(method)) assertMethods.push(method); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | var testObj = { |
michael@0 | 31 | isNice: function(){ |
michael@0 | 32 | return true; |
michael@0 | 33 | }, |
michael@0 | 34 | isBroken: function(){ |
michael@0 | 35 | return false; |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | Test.context("BDD-style testing",{ |
michael@0 | 40 | |
michael@0 | 41 | setup: function() { |
michael@0 | 42 | $('d').update('setup!'); |
michael@0 | 43 | moo++; |
michael@0 | 44 | }, |
michael@0 | 45 | |
michael@0 | 46 | teardown: function() { |
michael@0 | 47 | moo--; |
michael@0 | 48 | }, |
michael@0 | 49 | |
michael@0 | 50 | 'should run setup before each specification': function(){ |
michael@0 | 51 | assert($('d').innerHTML == 'setup!'); |
michael@0 | 52 | assert(moo == 1); |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | 'should run teardown after each specification': function(){ |
michael@0 | 56 | assert(moo == 1); |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | 'should provide extensions to tie in isSomething and respondsTo object methods': function(){ |
michael@0 | 60 | Object.extend(testObj, Test.BDDMethods); |
michael@0 | 61 | |
michael@0 | 62 | testObj.shouldBe('nice'); |
michael@0 | 63 | testObj.shouldNotBe('broken'); |
michael@0 | 64 | |
michael@0 | 65 | testObj.shouldRespondTo('isNice'); |
michael@0 | 66 | testObj.shouldRespondTo('isBroken'); |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | 'should automatically add extensions to strings': function(){ |
michael@0 | 70 | 'a'.shouldEqual('a'); |
michael@0 | 71 | 'a'.shouldNotEqual('b'); |
michael@0 | 72 | 'a'.shouldNotBeNull(); |
michael@0 | 73 | 'a'.shouldBeA(String); |
michael@0 | 74 | |
michael@0 | 75 | var aString = 'boo!'; |
michael@0 | 76 | aString.shouldEqual('boo!'); |
michael@0 | 77 | aString.shouldBeA(String); |
michael@0 | 78 | aString.shouldNotBeA(Number); |
michael@0 | 79 | }, |
michael@0 | 80 | |
michael@0 | 81 | 'should automatically add extensions to numbers': function(){ |
michael@0 | 82 | var n = 123; |
michael@0 | 83 | n.shouldEqual(123); |
michael@0 | 84 | n.shouldNotEqual(4); |
michael@0 | 85 | |
michael@0 | 86 | n.shouldBeA(Number); |
michael@0 | 87 | n.shouldNotBeA(Test); |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | 'should automatically add extensions to arrays': function(){ |
michael@0 | 91 | ['a'].shouldNotBeA(String); |
michael@0 | 92 | [1,2,3].shouldBeAn(Array); |
michael@0 | 93 | [1,2,3].shouldEqualEnum([1,2,3]); |
michael@0 | 94 | }, |
michael@0 | 95 | |
michael@0 | 96 | 'should support the eval() method': function(){ |
michael@0 | 97 | eval('2*2').shouldEqual(4); |
michael@0 | 98 | }, |
michael@0 | 99 | |
michael@0 | 100 | 'should support equality assertion': function(){ |
michael@0 | 101 | assertEqual(1, 1); |
michael@0 | 102 | assertEqual('a', 'a'); |
michael@0 | 103 | assertEqual(1, '1'); |
michael@0 | 104 | |
michael@0 | 105 | var x = 1; |
michael@0 | 106 | var y = 1; |
michael@0 | 107 | assertEqual(1, x) |
michael@0 | 108 | assertEqual(x, y); |
michael@0 | 109 | }, |
michael@0 | 110 | |
michael@0 | 111 | 'should provide all assertions': function(){ |
michael@0 | 112 | assertMethods.each(function(m){ |
michael@0 | 113 | assert(typeof this[m] == 'function'); |
michael@0 | 114 | }.bind(this)); |
michael@0 | 115 | }, |
michael@0 | 116 | |
michael@0 | 117 | 'should support deferred execution': function(){ |
michael@0 | 118 | wait(10,function(){ |
michael@0 | 119 | 'a'.shouldEqual('a'); |
michael@0 | 120 | }); |
michael@0 | 121 | |
michael@0 | 122 | wait(10,function(){ |
michael@0 | 123 | 'a'.shouldEqual('a'); |
michael@0 | 124 | wait(10,function(){ |
michael@0 | 125 | 'a'.shouldEqual('a'); |
michael@0 | 126 | wait(10,function(){ |
michael@0 | 127 | 'a'.shouldEqual('a'); |
michael@0 | 128 | }); |
michael@0 | 129 | }); |
michael@0 | 130 | }); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | }); |
michael@0 | 134 | |
michael@0 | 135 | // ]]> |
michael@0 | 136 | </script> |
michael@0 | 137 | </body> |
michael@0 | 138 | </html> |