dom/tests/mochitest/ajax/scriptaculous/test/unit/bdd_test.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/ajax/scriptaculous/test/unit/bdd_test.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     1.5 +        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     1.6 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     1.7 +<head>
     1.8 +  <title>script.aculo.us Unit test file</title>
     1.9 +  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    1.10 +  <script src="../../lib/prototype.js" type="text/javascript"></script>
    1.11 +  <script src="../../src/scriptaculous.js" type="text/javascript"></script>
    1.12 +  <script src="../../src/unittest.js" type="text/javascript"></script>
    1.13 +  <link rel="stylesheet" href="../test.css" type="text/css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +<h1>script.aculo.us Unit test file</h1>
    1.17 +
    1.18 +<!-- Log output -->
    1.19 +<div id="testlog"> </div>
    1.20 +
    1.21 +<div id="d">initial</div>
    1.22 +
    1.23 +<!-- Tests follow -->
    1.24 +<script type="text/javascript" language="javascript" charset="utf-8">
    1.25 +// <![CDATA[
    1.26 +var moo = 0;
    1.27 +
    1.28 +var assertMethods = [];
    1.29 +for(method in Test.Unit.Assertions.prototype) {
    1.30 +  if(/^assert/.test(method)) assertMethods.push(method);
    1.31 +}
    1.32 +
    1.33 +var testObj = {
    1.34 +  isNice: function(){
    1.35 +    return true;
    1.36 +  },
    1.37 +  isBroken: function(){
    1.38 +    return false;
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +Test.context("BDD-style testing",{
    1.43 +  
    1.44 +  setup: function() {
    1.45 +    $('d').update('setup!');
    1.46 +    moo++;
    1.47 +  },
    1.48 +  
    1.49 +  teardown: function() {
    1.50 +    moo--;
    1.51 +  },
    1.52 +  
    1.53 +  'should run setup before each specification': function(){
    1.54 +    assert($('d').innerHTML == 'setup!');
    1.55 +    assert(moo == 1);
    1.56 +  },
    1.57 +  
    1.58 +  'should run teardown after each specification': function(){
    1.59 +    assert(moo == 1);
    1.60 +  },
    1.61 +  
    1.62 +  'should provide extensions to tie in isSomething and respondsTo object methods': function(){
    1.63 +    Object.extend(testObj, Test.BDDMethods);
    1.64 +    
    1.65 +    testObj.shouldBe('nice');
    1.66 +    testObj.shouldNotBe('broken');
    1.67 +    
    1.68 +    testObj.shouldRespondTo('isNice');
    1.69 +    testObj.shouldRespondTo('isBroken');
    1.70 +  },
    1.71 +  
    1.72 +  'should automatically add extensions to strings': function(){
    1.73 +    'a'.shouldEqual('a');
    1.74 +    'a'.shouldNotEqual('b');
    1.75 +    'a'.shouldNotBeNull();
    1.76 +    'a'.shouldBeA(String);
    1.77 +    
    1.78 +    var aString = 'boo!';
    1.79 +    aString.shouldEqual('boo!');
    1.80 +    aString.shouldBeA(String);
    1.81 +    aString.shouldNotBeA(Number);
    1.82 +  },
    1.83 +  
    1.84 +  'should automatically add extensions to numbers': function(){
    1.85 +    var n = 123;    
    1.86 +    n.shouldEqual(123);
    1.87 +    n.shouldNotEqual(4);
    1.88 +    
    1.89 +    n.shouldBeA(Number);
    1.90 +    n.shouldNotBeA(Test);
    1.91 +  },
    1.92 +  
    1.93 +  'should automatically add extensions to arrays': function(){
    1.94 +    ['a'].shouldNotBeA(String);
    1.95 +    [1,2,3].shouldBeAn(Array);
    1.96 +    [1,2,3].shouldEqualEnum([1,2,3]);
    1.97 +  },
    1.98 +  
    1.99 +  'should support the eval() method': function(){
   1.100 +    eval('2*2').shouldEqual(4);
   1.101 +  },
   1.102 +  
   1.103 +  'should support equality assertion': function(){
   1.104 +    assertEqual(1, 1);
   1.105 +    assertEqual('a', 'a');
   1.106 +    assertEqual(1, '1');
   1.107 +    
   1.108 +    var x = 1;
   1.109 +    var y = 1;
   1.110 +    assertEqual(1, x)
   1.111 +    assertEqual(x, y);
   1.112 +  },
   1.113 +  
   1.114 +  'should provide all assertions': function(){
   1.115 +    assertMethods.each(function(m){
   1.116 +      assert(typeof this[m] == 'function');
   1.117 +    }.bind(this)); 
   1.118 +  },
   1.119 +  
   1.120 +  'should support deferred execution': function(){
   1.121 +    wait(10,function(){
   1.122 +      'a'.shouldEqual('a');
   1.123 +    });
   1.124 +    
   1.125 +    wait(10,function(){
   1.126 +      'a'.shouldEqual('a');
   1.127 +      wait(10,function(){
   1.128 +        'a'.shouldEqual('a');
   1.129 +        wait(10,function(){
   1.130 +          'a'.shouldEqual('a');
   1.131 +        });
   1.132 +      });
   1.133 +    });
   1.134 +  }
   1.135 +  
   1.136 +});
   1.137 +
   1.138 +// ]]>
   1.139 +</script>
   1.140 +</body>
   1.141 +</html>
   1.142 \ No newline at end of file

mercurial