jasmine-node
Advanced tools
Comparing version 1.3.0 to 1.3.1
(function() { | ||
var withoutAsync = {}; | ||
var withoutAsync = {}; | ||
["it", "beforeEach", "afterEach"].forEach(function(jasmineFunction) { | ||
withoutAsync[jasmineFunction] = jasmine.Env.prototype[jasmineFunction]; | ||
return jasmine.Env.prototype[jasmineFunction] = function() { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
var timeout = null; | ||
if (isLastArgumentATimeout(args)) { | ||
timeout = args.pop(); | ||
// The changes to the jasmine test runner causes undef to be passed when | ||
// calling all it()'s now. If the last argument isn't a timeout and the | ||
// last argument IS undefined, let's just pop it off. Since out of bounds | ||
// items are undefined anyways, *hopefully* removing an undef item won't | ||
// hurt. | ||
} else if (args[args.length-1] == undefined) { | ||
args.pop(); | ||
} | ||
if (isLastArgumentAnAsyncSpecFunction(args)) | ||
{ | ||
var specFunction = args.pop(); | ||
args.push(function() { | ||
return asyncSpec(specFunction, this, timeout); | ||
}); | ||
} | ||
return withoutAsync[jasmineFunction].apply(this, args); | ||
}; | ||
}); | ||
["it", "beforeEach", "afterEach"].forEach(function(jasmineFunction) { | ||
withoutAsync[jasmineFunction] = jasmine.Env.prototype[jasmineFunction]; | ||
return jasmine.Env.prototype[jasmineFunction] = function() { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
var timeout = null; | ||
if (isLastArgumentATimeout(args)) { | ||
timeout = args.pop(); | ||
// The changes to the jasmine test runner causes undef to be passed when | ||
// calling all it()'s now. If the last argument isn't a timeout and the | ||
// last argument IS undefined, let's just pop it off. Since out of bounds | ||
// items are undefined anyways, *hopefully* removing an undef item won't | ||
// hurt. | ||
} else if (args[args.length-1] == undefined) { | ||
args.pop(); | ||
} | ||
if (isLastArgumentAnAsyncSpecFunction(args)) | ||
{ | ||
var specFunction = args.pop(); | ||
args.push(function() { | ||
return asyncSpec(specFunction, this, timeout); | ||
}); | ||
} | ||
return withoutAsync[jasmineFunction].apply(this, args); | ||
}; | ||
}); | ||
function isLastArgumentATimeout(args) | ||
{ | ||
return args.length > 0 && (typeof args[args.length-1]) === "number"; | ||
} | ||
function isLastArgumentATimeout(args) | ||
{ | ||
return args.length > 0 && (typeof args[args.length-1]) === "number"; | ||
} | ||
function isLastArgumentAnAsyncSpecFunction(args) | ||
{ | ||
return args.length > 0 && (typeof args[args.length-1]) === "function" && args[args.length-1].length > 0; | ||
} | ||
function isLastArgumentAnAsyncSpecFunction(args) | ||
{ | ||
return args.length > 0 && (typeof args[args.length-1]) === "function" && args[args.length-1].length > 0; | ||
} | ||
function asyncSpec(specFunction, spec, timeout) { | ||
if (timeout == null) timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL || 1000; | ||
var done = false; | ||
spec.runs(function() { | ||
try { | ||
return specFunction(function(error) { | ||
done = true; | ||
if (error != null) return spec.fail(error); | ||
function asyncSpec(specFunction, spec, timeout) { | ||
if (timeout == null) timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL || 1000; | ||
var done = false; | ||
spec.runs(function() { | ||
try { | ||
return specFunction.call(spec, function(error) { | ||
done = true; | ||
if (error != null) return spec.fail(error); | ||
}); | ||
} catch (e) { | ||
done = true; | ||
throw e; | ||
} | ||
}); | ||
} catch (e) { | ||
done = true; | ||
throw e; | ||
} | ||
}); | ||
return spec.waitsFor(function() { | ||
if (done === true) { | ||
return true; | ||
} | ||
}, "spec to complete", timeout); | ||
}; | ||
return spec.waitsFor(function() { | ||
if (done === true) { | ||
return true; | ||
} | ||
}, "spec to complete", timeout); | ||
}; | ||
}).call(this); |
{ | ||
"name": "jasmine-node", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "DOM-less simple JavaScript BDD testing framework for Node", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -17,2 +17,3 @@ jasmine-node | ||
---------- | ||
* Async tests now run in the expected context instead of the global one | ||
* --config flag that allows you to assign variables to process.env | ||
@@ -136,2 +137,3 @@ * Terminal Reporters are now available in the Jasmine Object #184 | ||
* _1.3.1 - Fixed context for async tests (thanks to [omryn](https://github.com/omryn))_ | ||
* _1.3.0 - Added --config flag for changeable testing environments_ | ||
@@ -138,0 +140,0 @@ * _1.2.3 - Fixed #179, #184, #198, #199. Fixes autotest, afterEach in requirejs, terminal reporter is in jasmine object, done function missing in async tests_ |
@@ -67,4 +67,4 @@ describe('async-callback', function() { | ||
}); | ||
it("should finish after callback is called", function() { | ||
@@ -91,2 +91,26 @@ env.describe("it", function() { | ||
it('should run in the context of the current spec', function(){ | ||
var actualContext; | ||
var jasmineSpecContext; | ||
env.describe("it", function() { | ||
env.it("register context", function(done) { | ||
actualContext = this; | ||
jasmineSpecContext = env.currentSpec; | ||
env.expect(this).toBe(jasmineSpecContext); | ||
done(); | ||
}); | ||
}); | ||
env.currentRunner().execute(); | ||
waitsFor(function() { | ||
return env.currentRunner().results().totalCount > 0; | ||
}, 'tested jasmine env runner to run the test', 100); | ||
runs(function() { | ||
expect(actualContext).not.toBe(global); | ||
expect(actualContext).toBe(jasmineSpecContext); | ||
}); | ||
}); | ||
}); | ||
@@ -93,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144229
3985
144