Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moar tests

  • Loading branch information...
commit d1e382cf19b4f5f24773efbd58e6fe922f24349a 1 parent a531984
Rebecca Murphey authored April 11, 2012
38  tests/app/functions.js
... ...
@@ -0,0 +1,38 @@
  1
+define([ 'use!underscore' ], function(_) {
  2
+  describe("functions", function() {
  3
+    var sayIt = function(greeting, name, punctuation) {
  4
+          return greeting + ', ' + name + (punctuation || '!');
  5
+        },
  6
+        fn = function() {};
  7
+
  8
+    it("should be possible to use an array of arguments to call a function", function() {
  9
+      var result = fn([ 'Hello', 'Ellie', '!' ]);
  10
+      expect(result).to.be('Hello, Ellie!');
  11
+    });
  12
+
  13
+    it("should be possible to change the context in which a function is called", function() {
  14
+      var speak = function() {
  15
+            sayIt(this.greeting, this.name, '!!!');
  16
+          },
  17
+          obj = {
  18
+            greeting : 'Hello',
  19
+            name : 'Rebecca'
  20
+          };
  21
+
  22
+      // define a function for fn that calls the speak function such that the
  23
+      // following test will pass
  24
+      expect(fn()).to.be('Hello, Rebecca!');
  25
+    });
  26
+
  27
+    it("should be possible to return a function from a function", function() {
  28
+      // define a function for fn so that the following will pass
  29
+      expect(fn('Hello')('world')).to.be('Hello, world');
  30
+    });
  31
+
  32
+    it("should be possible to declare a 'partial' function", function() {
  33
+      // define a function for fn so that the following will pass
  34
+      var partial = fn(sayIt, 'Hello', 'Ellie');
  35
+      expect(partial('!!!')).to.be('Hello, Ellie!!!');
  36
+    });
  37
+  });
  38
+});
36  tests/app/objects.js
... ...
@@ -1,16 +1,16 @@
1 1
 define([ 'use!underscore' ], function(_) {
2 2
   describe("objects and context", function() {
3  
-    var a, b, fn = function() {};
  3
+    var a, b, C, fn;
4 4
 
5 5
     beforeEach(function() {
  6
+      fn = function() {};
  7
+
6 8
       a = {
7 9
         name : 'Matt',
8 10
         greeting : 'Hello',
9  
-        sayIt : function(preamble, punctuation) {
10  
-          return  (preamble || '') +
11  
-                  this.name + ', ' +
12  
-                  this.greeting +
13  
-                  (punctuation || '!');
  11
+        sayIt : function() {
  12
+          return  this.name + ', ' +
  13
+                  this.greeting + '!';
14 14
         }
15 15
       };
16 16
 
@@ -18,16 +18,30 @@ define([ 'use!underscore' ], function(_) {
18 18
         name : 'Rebecca',
19 19
         greeting : 'Yo'
20 20
       };
  21
+
  22
+      C = function(name) {
  23
+        this.name = name;
  24
+        return this;
  25
+      };
21 26
     });
22 27
 
23  
-    it("should be able to alter the context in which a function runs", function() {
24  
-      fn = function() { };
  28
+    it("should be able to alter the context in which a method runs", function() {
  29
+      // define a function for fn so that the following will pass
25 30
       expect(fn()).to.be('Yo, Rebecca!');
26 31
     });
27 32
 
28  
-    it("should be able to pass in arguments stored in an array", function() {
29  
-      fn = function() { };
30  
-      expect(fn()).to.be('Why Hello, Matt!!!');
  33
+    it("should be able to alter multiple objects at once", function() {
  34
+      // define a function for fn so that the following will pass
  35
+      var obj1 = new C('Rebecca'),
  36
+          obj2 = new C('Melissa'),
  37
+          greeting = "What's up";
  38
+
  39
+      fn(greeting);
  40
+
  41
+      expect(obj1.greeting).to.be(greeting);
  42
+      expect(obj2.greeting).to.be(greeting);
  43
+      expect(new C('Ellie').greeting).to.be(greeting);
31 44
     });
  45
+
32 46
   });
33 47
 });
11  tests/runner.js
... ...
@@ -1,14 +1,11 @@
1 1
 var tests = [
2 2
   // link to test files here
3 3
 
4  
-  // 'tests/app/arrays',
5  
-  // 'tests/app/objects',
6  
-  // 'tests/app/async',
  4
+  'tests/app/arrays',
  5
+  'tests/app/objects',
  6
+  'tests/app/functions',
  7
+  'tests/app/async',
7 8
   'tests/app/views'
8  
-
9  
-  // 'tests/app/models',
10  
-  // 'tests/app/prototypes',
11  
-  // 'tests/app/functions'
12 9
 ];
13 10
 
14 11
 require(tests, function() {

0 notes on commit d1e382c

Please sign in to comment.
Something went wrong with that request. Please try again.