Throw a recognizable Error message when fail outside of a spec.
Fixes #1017
This commit is contained in:
@@ -1148,6 +1148,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
|
if (!currentRunnable()) {
|
||||||
|
throw new Error('\'fail\' was used when there was no current spec, this could be because an asynchronous test timed out');
|
||||||
|
}
|
||||||
|
|
||||||
var message = 'Failed';
|
var message = 'Failed';
|
||||||
if (error) {
|
if (error) {
|
||||||
message += ': ';
|
message += ': ';
|
||||||
|
|||||||
@@ -212,6 +212,23 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) {
|
||||||
|
var env = new jasmineUnderTest.Env(),
|
||||||
|
reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(done);
|
||||||
|
env.addReporter(reporter);
|
||||||
|
|
||||||
|
env.describe("A Suite", function() {
|
||||||
|
env.it("an async spec that is actually synchronous", function(underTestCallback) {
|
||||||
|
underTestCallback();
|
||||||
|
});
|
||||||
|
expect(function() { env.fail(); }).toThrowError(/'fail' was used when there was no current spec/);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it("calls associated befores/specs/afters with the same 'this'", function(done) {
|
it("calls associated befores/specs/afters with the same 'this'", function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
var env = new jasmineUnderTest.Env();
|
||||||
|
|||||||
@@ -532,6 +532,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
|
if (!currentRunnable()) {
|
||||||
|
throw new Error('\'fail\' was used when there was no current spec, this could be because an asynchronous test timed out');
|
||||||
|
}
|
||||||
|
|
||||||
var message = 'Failed';
|
var message = 'Failed';
|
||||||
if (error) {
|
if (error) {
|
||||||
message += ': ';
|
message += ': ';
|
||||||
|
|||||||
Reference in New Issue
Block a user