Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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]
  • Loading branch information...
commit 7d93541c09786163b1470b3212c17b6db37b7352 1 parent 29aad76
@sheelc sheelc authored
Showing with 18 additions and 0 deletions.
  1. +14 −0 spec/core/integration/EnvSpec.js
  2. +4 −0 src/core/Env.js
View
14 spec/core/integration/EnvSpec.js
@@ -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();
+ });
});
View
4 src/core/Env.js
@@ -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);
};
Please sign in to comment.
Something went wrong with that request. Please try again.