Throw a more specific error when 'expect' is used without a currentSpec
If an async test has timed-out, there could still be some expectations that are scheduled to run after the fact in which case curerntSpec will be null. Rather than the type error that would result, we now indicate that 'expect' was used at an unexpected time. This also helps cases where an 'expect' is being used at a top-level, showing an error message in the console for this case as well. [fixes #602]
This commit is contained in:
@@ -488,5 +488,19 @@ describe("Env integration", function() {
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {
|
||||
var env = new j$.Env();
|
||||
|
||||
env.describe("A Suite", function() {
|
||||
env.it("an async spec that is actually synchronous", function(underTestCallback) {
|
||||
underTestCallback();
|
||||
expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -317,6 +317,10 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.expect = function(actual) {
|
||||
if (!currentSpec) {
|
||||
throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out');
|
||||
}
|
||||
|
||||
return currentSpec.expect(actual);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user