From 6f38eebd601244b557756c27f3a4aa5c7ea26aa1 Mon Sep 17 00:00:00 2001 From: Justin Taylor Date: Thu, 4 Oct 2012 10:41:31 -0700 Subject: [PATCH] AMD module testing for BBB --- .../bbb/all/templates/test/index.html | 8 +- .../bbb/all/templates/test/runner/mocha.js | 19 ++- .../bbb/all/templates/test/spec/example.js | 112 ++++++++++-------- 3 files changed, 84 insertions(+), 55 deletions(-) diff --git a/lib/generators/bbb/all/templates/test/index.html b/lib/generators/bbb/all/templates/test/index.html index c0f58e9f..8b6e83a5 100644 --- a/lib/generators/bbb/all/templates/test/index.html +++ b/lib/generators/bbb/all/templates/test/index.html @@ -8,13 +8,13 @@
- + + - - - + + diff --git a/lib/generators/bbb/all/templates/test/runner/mocha.js b/lib/generators/bbb/all/templates/test/runner/mocha.js index 16edb68a..ee47e698 100644 --- a/lib/generators/bbb/all/templates/test/runner/mocha.js +++ b/lib/generators/bbb/all/templates/test/runner/mocha.js @@ -1,4 +1,19 @@ -(function() { +require({ + + // Ensure you point to where your spec folder is, base directory is app/scripts, + // which is why ../../test is necessary + paths: { + spec: '../../test/spec' + } + +}, [ + +// Load specs +'spec/example' + +], function() { + 'use strict'; + var runner = mocha.run(); if(!window.PHANTOMJS) return; @@ -38,4 +53,4 @@ var args = [].slice.call(arguments); alert(JSON.stringify(args)); } -})(); +}); diff --git a/lib/generators/bbb/all/templates/test/spec/example.js b/lib/generators/bbb/all/templates/test/spec/example.js index 3984fe53..af40dec1 100644 --- a/lib/generators/bbb/all/templates/test/spec/example.js +++ b/lib/generators/bbb/all/templates/test/spec/example.js @@ -1,77 +1,91 @@ -describe("one tautology", function() { - it("is a tautology", function() { - expect(true).to.be.true; - }); +define([ - describe("is awesome", function() { - it("is awesome", function() { - expect(1).to.equal(1); - }); - }); -}); + // import the module to be tested + '../../app/scripts/app' -describe("simple tests", function() { - it("increments", function() { - var mike = 0; +], function(module) { + 'use strict'; - expect(mike++ === 0).to.be.true; - expect(mike === 1).to.be.true; + describe("module", function() { + it("has trigger method", function() { + expect(module.trigger).to.be.a("function") + }); }); - it("increments (improved)", function() { - var mike = 0; + describe("one tautology", function() { + it("is a tautology", function() { + expect(true).to.be.true; + }); - expect(mike++).to.equal(0); - expect(mike).to.equal(1); + describe("is awesome", function() { + it("is awesome", function() { + expect(1).to.equal(1); + }); + }); }); -}); -describe("setUp/tearDown", function() { - beforeEach(function() { - // console.log("Before"); - }); + describe("simple tests", function() { + it("increments", function() { + var mike = 0; - afterEach(function() { - // console.log("After"); - }); + expect(mike++ === 0).to.be.true; + expect(mike === 1).to.be.true; + }); - it("example", function() { - // console.log("During"); + it("increments (improved)", function() { + var mike = 0; + + expect(mike++).to.equal(0); + expect(mike).to.equal(1); + }); }); describe("setUp/tearDown", function() { beforeEach(function() { - // console.log("Before2"); + // console.log("Before"); }); afterEach(function() { - // console.log("After2"); + // console.log("After"); }); it("example", function() { - // console.log("During Nested"); + // console.log("During"); + }); + + describe("setUp/tearDown", function() { + beforeEach(function() { + // console.log("Before2"); + }); + + afterEach(function() { + // console.log("After2"); + }); + + it("example", function() { + // console.log("During Nested"); + }); }); }); -}); -describe("async", function() { - it("multiple async", function(done) { - var semaphore = 2; + describe("async", function() { + it("multiple async", function(done) { + var semaphore = 2; - setTimeout(function() { - expect(true).to.be.true; - semaphore--; - }, 500); + setTimeout(function() { + expect(true).to.be.true; + semaphore--; + }, 500); - setTimeout(function() { - expect(true).to.be.true; - semaphore--; - }, 500); + setTimeout(function() { + expect(true).to.be.true; + semaphore--; + }, 500); - setTimeout(function() { - expect(semaphore).to.equal(0); - done(); - }, 600); + setTimeout(function() { + expect(semaphore).to.equal(0); + done(); + }, 600); + }); }); }); -