From 8db02803da60f35daa571d17203c9c463641c6fe Mon Sep 17 00:00:00 2001 From: Rebecca Murphey Date: Wed, 11 Apr 2012 20:19:51 -0400 Subject: [PATCH] flow control, module tests wip; more objects tests --- tests/app/async.js | 6 ++---- tests/app/flowControl.js | 42 ++++++++++++++++++++++++++++++++++++++++ tests/app/modules.js | 17 ++++++++++++++++ tests/app/objects.js | 9 +++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tests/app/flowControl.js create mode 100644 tests/app/modules.js diff --git a/tests/app/async.js b/tests/app/async.js index 495c6d7d3..4350918e9 100644 --- a/tests/app/async.js +++ b/tests/app/async.js @@ -1,9 +1,9 @@ define([ 'jquery', 'use!underscore' ], function($, _) { describe("async behavior", function() { - var promise, fn = function() { }; + var promise, fn; beforeEach(function() { - + fn = function() { }; }); it("you should understand how to uses 'promises'", function(done) { @@ -36,7 +36,5 @@ define([ 'jquery', 'use!underscore' ], function($, _) { tests(); }); - }); - }); diff --git a/tests/app/flowControl.js b/tests/app/flowControl.js new file mode 100644 index 000000000..d45022239 --- /dev/null +++ b/tests/app/flowControl.js @@ -0,0 +1,42 @@ +define([ 'use!underscore' ], function(_) { + describe("flow control", function() { + var fn; + + beforeEach(function() { + fn = function() { }; + }); + + it("you should be able to conditionally branch your code", function() { + fn = function() { + // write a function that receives a number as its argument; + // if the number is divisible by 3, the function should return 'fizz'; + // if the number is divisible by 5, the function should return 'buzz'; + // if the number is divisible the 3 and 5, the function should return + // 'fizzbuzz'; + // otherwise the function should return the number + }; + + // replace the following test with tests that prove your function works + expect(fn()).to.be.ok(); + }); + + it("you should be able to work with logical operators", function() { + var and = function(val1, val2) { + // write a function that makes the tests below pass + }, + + or = function(val1, val2) { + // write a function that makes the tests below pass + }; + + expect(and(false, false)).not.to.be.ok(); + expect(and(true, false)).not.to.be.ok(); + expect(and(true, true)).to.be.ok(); + + expect(or(true, false)).to.be.ok(); + expect(or(true, true)).to.be.ok(); + expect(or(false, false)).not.to.be.ok(); + }); + }); + +}); diff --git a/tests/app/modules.js b/tests/app/modules.js new file mode 100644 index 000000000..ce3776dbf --- /dev/null +++ b/tests/app/modules.js @@ -0,0 +1,17 @@ +define([ 'use!underscore' ], function(_) { + describe("the module pattern", function() { + var fn = function() {}; + + it("you should be able to create a function that returns a module", function() { + fn = function() { + // write a function that makes the tests pass + }; + + var module = fn('hello', 'matt'); + expect(module.name).to.be.ok(); + expect(module.greeting).to.be.ok(); + expect(module.sayIt).to.be.a('function'); + expect(module.sayIt()).to.be('hello, matt'); + }); + }); +}); diff --git a/tests/app/objects.js b/tests/app/objects.js index 74b2235b3..6b68f3647 100644 --- a/tests/app/objects.js +++ b/tests/app/objects.js @@ -43,5 +43,14 @@ define([ 'use!underscore' ], function(_) { expect(new C('Ellie').greeting).to.be(greeting); }); + it("you should be able to iterate over an object's properties", function() { + // define a function for fn so that the following will pass + var obj = { + foo : 'bar', + baz : 'bim' + }; + + expect(fn()).to.eql([ 'foo: bar', 'baz: bim' ]); + }); }); });