root/public/javascripts/scriptaculous/test/unit/bdd_test.html

Revision 1, 3.5 kB (checked in by falcon, 17 years ago)

Version one -> initial work from the laptop.

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