Permalink
Browse files

moar tests

  • Loading branch information...
1 parent a531984 commit d1e382cf19b4f5f24773efbd58e6fe922f24349a @rmurphey rmurphey committed Apr 11, 2012
Showing with 67 additions and 18 deletions.
  1. +38 −0 tests/app/functions.js
  2. +25 −11 tests/app/objects.js
  3. +4 −7 tests/runner.js
View
@@ -0,0 +1,38 @@
+define([ 'use!underscore' ], function(_) {
+ describe("functions", function() {
+ var sayIt = function(greeting, name, punctuation) {
+ return greeting + ', ' + name + (punctuation || '!');
+ },
+ fn = function() {};
+
+ it("should be possible to use an array of arguments to call a function", function() {
+ var result = fn([ 'Hello', 'Ellie', '!' ]);
+ expect(result).to.be('Hello, Ellie!');
+ });
+
+ it("should be possible to change the context in which a function is called", function() {
+ var speak = function() {
+ sayIt(this.greeting, this.name, '!!!');
+ },
+ obj = {
+ greeting : 'Hello',
+ name : 'Rebecca'
+ };
+
+ // define a function for fn that calls the speak function such that the
+ // following test will pass
+ expect(fn()).to.be('Hello, Rebecca!');
+ });
+
+ it("should be possible to return a function from a function", function() {
+ // define a function for fn so that the following will pass
+ expect(fn('Hello')('world')).to.be('Hello, world');
+ });
+
+ it("should be possible to declare a 'partial' function", function() {
+ // define a function for fn so that the following will pass
+ var partial = fn(sayIt, 'Hello', 'Ellie');
+ expect(partial('!!!')).to.be('Hello, Ellie!!!');
+ });
+ });
+});
View
@@ -1,33 +1,47 @@
define([ 'use!underscore' ], function(_) {
describe("objects and context", function() {
- var a, b, fn = function() {};
+ var a, b, C, fn;
beforeEach(function() {
+ fn = function() {};
+
a = {
name : 'Matt',
greeting : 'Hello',
- sayIt : function(preamble, punctuation) {
- return (preamble || '') +
- this.name + ', ' +
- this.greeting +
- (punctuation || '!');
+ sayIt : function() {
+ return this.name + ', ' +
+ this.greeting + '!';
}
};
b = {
name : 'Rebecca',
greeting : 'Yo'
};
+
+ C = function(name) {
+ this.name = name;
+ return this;
+ };
});
- it("should be able to alter the context in which a function runs", function() {
- fn = function() { };
+ it("should be able to alter the context in which a method runs", function() {
+ // define a function for fn so that the following will pass
expect(fn()).to.be('Yo, Rebecca!');
});
- it("should be able to pass in arguments stored in an array", function() {
- fn = function() { };
- expect(fn()).to.be('Why Hello, Matt!!!');
+ it("should be able to alter multiple objects at once", function() {
+ // define a function for fn so that the following will pass
+ var obj1 = new C('Rebecca'),
+ obj2 = new C('Melissa'),
+ greeting = "What's up";
+
+ fn(greeting);
+
+ expect(obj1.greeting).to.be(greeting);
+ expect(obj2.greeting).to.be(greeting);
+ expect(new C('Ellie').greeting).to.be(greeting);
});
+
});
});
View
@@ -1,14 +1,11 @@
var tests = [
// link to test files here
- // 'tests/app/arrays',
- // 'tests/app/objects',
- // 'tests/app/async',
+ 'tests/app/arrays',
+ 'tests/app/objects',
+ 'tests/app/functions',
+ 'tests/app/async',
'tests/app/views'
-
- // 'tests/app/models',
- // 'tests/app/prototypes',
- // 'tests/app/functions'
];
require(tests, function() {

0 comments on commit d1e382c

Please sign in to comment.