GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A JavaScript BDD Testing Library
Homepage: http://www.yehudakatz.com
Clone URL: git://github.com/wycats/jspec.git
Phil Hagelberg (author)
Tue Feb 05 15:41:03 -0800 2008
commit  163aeb2c126c6a140f292cf1a4849a168ab5ef27
tree    a034a63161f72abff7720e2f9b8dbaab30604a0c
parent  2c34a20fe1699ecdefb07b3bde51906da00ffc0b
jspec / tester2.html
100644 66 lines (57 sloc) 2.204 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
 
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>tester2</title>
  <meta name="generator" content="TextMate http://macromates.com/">
  <meta name="author" content="Yehuda Katz">
  <script src="jspec.js"></script>
  <script>
    window.onload = function() {
      jspec.describe("JSpec", function() {
        it("should support ==", function() {
          expect(1).to("==", 1);
          var arr = [];
          expect(arr).to("==", arr);
          var obj = new Object;
          expect(obj).to("==", obj);
          expect(document).to("==", document);
        });
      
        it("should support include", function() {
         expect([1,2,3,4,5]).to("include", 3);
         expect([1,2,3,4,5]).not_to("include", 3);
         expect(document.getElementsByTagName("div")).to("include", document.getElementById("hello"))
        });
        
        it("should support exists", function() {
         expect(document).to("exist");
        });
 
        it("should support pending specs");
        
        jspec.matchers["have_tag_name"] = {
         describe: function(self, target, not) {
           return jspec.print_object(self) + " should " + (not ? "not " : "") + "have " + target + " as its tag name."
         },
         matches: function(self, target) {
           return (self.tagName && self.tagName == target) ? true : false;
         },
         failure_message: function(self, target, not) {
           return "Expected " + jspec.print_object(self) + (not ? " not " : " ") + "to have " + target + " as its tag name," +
             " but was " + self.tagName;
         }
        };
        
        it("should support custom matchers", function() {
         expect(document.getElementById("wrapper")).to("have_tag_name", "DIV");
         expect(document.getElementById("wrapper")).to("have_tag_name", "SPAN");
         expect(document.getElementById("wrapper")).not_to("have_tag_name", "SPAN");
        });
      });
    };
  </script>  
  <style type="text/css">
    div#wrapper { display: none ;}
  </style>
</head>
<body>
 
  <div id="wrapper"><div id="hello">Hello</div></div>
 
</body>
</html>