public
Description: A jQuery plugin for Morphic programming
Homepage:
Clone URL: git://github.com/nkallen/effen.git
effen / fn_spec.html
100644 48 lines (48 sloc) 1.79 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
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>fn Test</title>
    <meta name="author" content="Nick Kallen">
    <script src="jspec.js"></script>
    <script src="jquery-1.2.3.js"></script>
    <script src="jquery.fn.js"></script>
    <script>
      $(document).ready(function() {
        jspec.describe("fn", function() {
          it("registers and applies a function bound to a name", function() {
            var element = $("<div></div>");
            element.fn({ name: function() { return "function invoked" } });
            element.fn('name').should("==", "function invoked");
          });
          it("registers and applies a function of any arity", function() {
            var element = $("<div></div>");
            element.fn({ name: function(a, b, c) { return [a, b, c] } });
            element.fn('name', 1, 2, 3).should("eq", [1, 2, 3]);
          });
          it("registers many functions", function() {
            var element = $("<div></div>");
            element.fn({
              name1: function() { return 1 },
              name2: function() { return 2 }
            });
            element.fn('name1').should("==", 1);
            element.fn('name2').should("==", 2);
          });
          it("applies bound functions to each item in a collection", function() {
            var elements = $("<div></div>").add($("<div></div>"));
            var i = 0;
            elements.fn({ call: function() { i++ } });
            elements.fn('call');
            i.should("==", 2);
          });
        });
      });
    </script>
  </head>
    <style type="text/css">
      div#wrapper { display: none ;}
    </style>
  <body>
    <div id="wrapper"><div id="hello">Hello</div></div>
  </body>
</html>