diff options
author | Wilson Page <wilsonpage@me.com> | 2013-08-27 12:29:21 +0100 |
---|---|---|
committer | Wilson Page <wilsonpage@me.com> | 2013-08-27 12:29:21 +0100 |
commit | b864963d7ed7e68a7ad1a8ab1cead270d08bdc2e (patch) | |
tree | 4f37bac32fdc7ad2b0ebc45be92e290dbe27a703 | |
parent | 90f6727f1f5470bc4c87714b4dd1653c69e907ff (diff) | |
download | fastdom-b864963d7ed7e68a7ad1a8ab1cead270d08bdc2e.zip fastdom-b864963d7ed7e68a7ad1a8ab1cead270d08bdc2e.tar.gz fastdom-b864963d7ed7e68a7ad1a8ab1cead270d08bdc2e.tar.bz2 |
Convert test suit to Mocha
-rw-r--r-- | package.json | 10 | ||||
-rw-r--r-- | test/index.html | 27 | ||||
-rw-r--r-- | test/setup.js | 6 | ||||
-rw-r--r-- | test/test.clear.js | 38 | ||||
-rw-r--r-- | test/test.set.js | 63 |
5 files changed, 87 insertions, 57 deletions
diff --git a/package.json b/package.json index 708603c..0ad3b78 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.3.1", "main": "lib/dom-batch.js", "scripts": { - "test": "./node_modules/.bin/grunt buster" + "test": "./node_modules/.bin/mocha-phantomjs test/index.html" }, "homepage": "https://github.com/wilsonpage/dom-batch", "author": { @@ -17,9 +17,9 @@ }, "license": "MIT", "devDependencies": { - "grunt-buster": "~0.2.1", - "grunt-cli": "~0.1.9", - "grunt": "~0.4.1", - "buster": "~0.6.5" + "mocha": "~1.12.0", + "sinon": "~1.7.3", + "chai": "~1.7.2", + "mocha-phantomjs": "~3.1.2" } } diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..84c8da8 --- /dev/null +++ b/test/index.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Mocha Tests</title> + <link rel="stylesheet" href="../node_modules/mocha/mocha.css" /> +</head> +<body> + <div id="mocha"></div> + <script src="../node_modules/mocha/mocha.js"></script> + <script src="../node_modules/chai/chai.js"></script> + <script src="../node_modules/sinon/lib/sinon.js"></script> + <script src="../node_modules/sinon/lib/sinon/match.js"></script> + <script src="../node_modules/sinon/lib/sinon/spy.js"></script> + <script>mocha.setup('tdd')</script> + <script src="../lib/dom-batch.js"></script> + <script src="setup.js"></script> + <script src="test.set.js"></script> + <script src="test.clear.js"></script> + <script> + mocha.checkLeaks(); + + if (window.mochaPhantomJS) mochaPhantomJS.run(); + else mocha.run(); + </script> +</body> +</html>
\ No newline at end of file diff --git a/test/setup.js b/test/setup.js index a28247b..742c2c5 100644 --- a/test/setup.js +++ b/test/setup.js @@ -5,4 +5,8 @@ var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || function(cb) { window.setTimeout(cb, 1000 / 60); }; -var DomBatch = dom.constructor;
\ No newline at end of file +// Make constructor +var DomBatch = dom.constructor; + +// Alias chai.assert +var assert = chai.assert;
\ No newline at end of file diff --git a/test/test.clear.js b/test/test.clear.js index d5599d5..bd826f4 100644 --- a/test/test.clear.js +++ b/test/test.clear.js @@ -1,60 +1,60 @@ -buster.testCase('DomBatch - Clearing', { +suite('Clear', function(){ - "Should not run 'read' job if cleared (sync)": function(done) { + test("Should not run 'read' job if cleared (sync)", function(done) { var dom = new DomBatch(); - var read = this.spy(); + var read = sinon.spy(); dom.read(read); dom.clearRead(read); raf(function() { - refute(read.called); + assert(!read.called); done(); }); - }, + }); - "Should fail silently if job not found in queue": function(done) { + test("Should fail silently if job not found in queue", function(done) { var dom = new DomBatch(); - var read = this.spy(); - var read2 = this.spy(); + var read = sinon.spy(); + var read2 = sinon.spy(); dom.read(read); dom.clearRead(read2); raf(function() { - refute(read2.called); + assert(!read2.called); done(); }); - }, + }); - "Should not run 'write' job if cleared (async)": function(done) { + test("Should not run 'write' job if cleared (async)", function(done) { var dom = new DomBatch(); - var read = this.spy(); - var write = this.spy(); + var read = sinon.spy(); + var write = sinon.spy(); dom.write(write); dom.read(function() { dom.clearWrite(write); raf(function() { - refute(read.called); + assert(!read.called); done(); }); }); - }, + }); - "Should not run 'write' job if cleared": function(done) { + test("Should not run 'write' job if cleared", function(done) { var dom = new DomBatch(); - var write = this.spy(); + var write = sinon.spy(); dom.write(write); dom.clearWrite(write); raf(function() { - refute(write.called); + assert(!write.called); done(); }); - } + }); });
\ No newline at end of file diff --git a/test/test.set.js b/test/test.set.js index 0b4fa88..9b5ba4d 100644 --- a/test/test.set.js +++ b/test/test.set.js @@ -1,29 +1,28 @@ -var DomBatch = dom.constructor; -buster.testCase('DomBatch', { +suite('Set', function() { - "Should run reads before writes": function(done) { + test("Should run reads before writes", function(done) { var dom = new DomBatch(); - var read = this.spy(function() { - refute(write.called); + var read = sinon.spy(function() { + assert(!write.called); }); - var write = this.spy(function() { + var write = sinon.spy(function() { assert(read.called); done(); }); dom.read(read); dom.write(write); - }, + }); - "Should call all reads together, followed by all writes": function(done) { + test("Should call all reads together, followed by all writes", function(done) { var dom = new DomBatch(); - var read1 = this.spy(); - var read2 = this.spy(); - var write1 = this.spy(); - var write2 = this.spy(); + var read1 = sinon.spy(); + var read2 = sinon.spy(); + var write1 = sinon.spy(); + var write2 = sinon.spy(); // Assign unsorted dom.read(read1); @@ -40,11 +39,11 @@ buster.testCase('DomBatch', { assert(write1.calledBefore(write2)); done(); }); - }, + }); - "Should call a read in the same frame if scheduled inside a read callback": function(done) { + test("Should call a read in the same frame if scheduled inside a read callback", function(done) { var dom = new DomBatch(); - var cb = this.spy(); + var cb = sinon.spy(); dom.read(function() { @@ -57,15 +56,15 @@ buster.testCase('DomBatch', { // the RAF callback has not // yet been fired. dom.read(function() { - refute(cb.called); + assert(!cb.called); done(); }); }); - }, + }); - "Should call a write in the same frame if scheduled inside a read callback": function(done) { + test("Should call a write in the same frame if scheduled inside a read callback", function(done) { var dom = new DomBatch(); - var cb = this.spy(); + var cb = sinon.spy(); dom.read(function() { @@ -78,15 +77,15 @@ buster.testCase('DomBatch', { // the RAF callback has not // yet been fired. dom.write(function() { - refute(cb.called); + assert(!cb.called); done(); }); }); - }, + }); - "Should call a read in the *next* frame if scheduled inside a write callback": function(done) { + test("Should call a read in the *next* frame if scheduled inside a write callback", function(done) { var dom = new DomBatch(); - var cb = this.spy(); + var cb = sinon.spy(); dom.write(function() { @@ -102,27 +101,27 @@ buster.testCase('DomBatch', { done(); }); }); - }, + }); - "Should call a 'read' callback with the given context": function(done) { + test("Should call a 'read' callback with the given context", function(done) { var dom = new DomBatch(); - var cb = this.spy(); + var cb = sinon.spy(); var ctx = { foo: 'bar' }; dom.read(function() { - assert.equals(this.foo, 'bar'); + assert.equal(this.foo, 'bar'); done(); }, ctx); - }, + }); - "Should call a 'write' callback with the given context": function(done) { + test("Should call a 'write' callback with the given context", function(done) { var dom = new DomBatch(); - var cb = this.spy(); + var cb = sinon.spy(); var ctx = { foo: 'bar' }; dom.write(function() { - assert.equals(this.foo, 'bar'); + assert.equal(this.foo, 'bar'); done(); }, ctx); - } + }); });
\ No newline at end of file |