diff options
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/nextTick.js | 38 | ||||
-rw-r--r-- | mocha_test/setImmediate.js | 24 |
2 files changed, 62 insertions, 0 deletions
diff --git a/mocha_test/nextTick.js b/mocha_test/nextTick.js new file mode 100644 index 0000000..b428822 --- /dev/null +++ b/mocha_test/nextTick.js @@ -0,0 +1,38 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe("nextTick", function () { + + it('basics', function(done){ + var call_order = []; + async.nextTick(function(){call_order.push('two');}); + call_order.push('one'); + setTimeout(function(){ + expect(call_order).to.eql(['one','two']); + done(); + }, 50); + }); + + it('nextTick in the browser', function(done){ + if (!process.browser) { + // skip this test in node + return done(); + } + + var call_order = []; + async.nextTick(function(){call_order.push('two');}); + + call_order.push('one'); + setTimeout(function(){ + expect(call_order).to.eql(['one','two']); + done(); + }, 50); + }); + + it("extra args", function (done) { + async.nextTick(function (a, b, c) { + expect([a, b, c]).to.eql([1, 2, 3]); + done(); + }, 1, 2, 3); + }); +}); diff --git a/mocha_test/setImmediate.js b/mocha_test/setImmediate.js new file mode 100644 index 0000000..854111a --- /dev/null +++ b/mocha_test/setImmediate.js @@ -0,0 +1,24 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe("setImmediate", function () { + + it('basics', function(done){ + var call_order = []; + async.setImmediate(function(){call_order.push('two');}); + call_order.push('one'); + + setTimeout(function(){ + expect(call_order).to.eql(['one','two']); + done(); + }, 25); + }); + + it("extra args", function (done) { + async.setImmediate(function (a, b, c) { + expect([a, b, c]).to.eql([1, 2, 3]); + done(); + }, 1, 2, 3); + }); + +}); |