Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fixed errors thrown in sync test-cases due to nextTick

Tj Holowaychuk7c7357a52e81
diff --git a/lib/runner.js b/lib/runner.js
index 5c919e6c..2a5f158e 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -165,24 +165,23 @@ Runner.prototype.runTest = function(fn){
var test = this.test
, self = this;
- // run the test
- try {
- // async
- if (test.async) return test.run(function(err){
- if (test.finished) {
- self.fail(test, new Error('done() called multiple times'));
- return;
- }
- fn(err);
- });
- // sync
- process.nextTick(function(){
+ // async
+ if (test.async) return test.run(function(err){
+ if (test.finished) {
+ self.fail(test, new Error('done() called multiple times'));
+ return;
+ }
+ fn(err);
+ });
+ // sync
+ process.nextTick(function(){
+ try {
test.run();
fn();
- });
- } catch (err) {
- fn(err);
- }
+ } catch (err) {
+ fn(err);
+ }
+ });
};
/**
diff --git a/mocha.js b/mocha.js
index 8dfc32a4..7557a785 100644
--- a/mocha.js
+++ b/mocha.js
@@ -1579,24 +1579,23 @@ Runner.prototype.runTest = function(fn){
var test = this.test
, self = this;
- // run the test
- try {
- // async
- if (test.async) return test.run(function(err){
- if (test.finished) {
- self.fail(test, new Error('done() called multiple times'));
- return;
- }
- fn(err);
- });
- // sync
- process.nextTick(function(){
+ // async
+ if (test.async) return test.run(function(err){
+ if (test.finished) {
+ self.fail(test, new Error('done() called multiple times'));
+ return;
+ }
+ fn(err);
+ });
+ // sync
+ process.nextTick(function(){
+ try {
test.run();
fn();
- });
- } catch (err) {
- fn(err);
- }
+ } catch (err) {
+ fn(err);
+ }
+ });
};
/**
diff --git a/test/browser/array.js b/test/browser/array.js
index 388149e7..5c1f1426 100644
--- a/test/browser/array.js
+++ b/test/browser/array.js
@@ -17,7 +17,7 @@ describe('Array', function(){
describe('#pop()', function(){
it('should remove and return the last value', function(){
var arr = [1,2,3];
- assert(arr.pop() == 3);
+ assert(arr.pop() == 5);
})
})
})