Skip to content

Commit

Permalink
Merge pull request #80 from findzen/master
Browse files Browse the repository at this point in the history
AMD module testing for BBB
  • Loading branch information
addyosmani committed Oct 4, 2012
2 parents 632a59e + 6f38eeb commit 2c61317
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 55 deletions.
8 changes: 4 additions & 4 deletions lib/generators/bbb/all/templates/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<body>
<div id="mocha"></div>
<script src="lib/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<!-- define globals for mocha -->
<script>mocha.setup({ ui: 'bdd', globals: ['_', '$', 'jQuery*', 'Backbone', 'JST'] })</script>
<!-- assertion framework -->
<script src="lib/chai.js"></script>
<script>expect = chai.expect</script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script src="spec/example.js"></script>
<!-- Load application -->
<script data-main="../app/scripts/config" src="../app/scripts/libs/require.js"></script>
<!-- trigger the mocha runner -->
<script src="runner/mocha.js"></script>
</body>
Expand Down
19 changes: 17 additions & 2 deletions lib/generators/bbb/all/templates/test/runner/mocha.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,4 +53,4 @@
var args = [].slice.call(arguments);
alert(JSON.stringify(args));
}
})();
});
112 changes: 63 additions & 49 deletions lib/generators/bbb/all/templates/test/spec/example.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 2c61317

Please sign in to comment.