diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index 3aef1360..5381fddc 100644 --- a/spec/core/integration/EnvSpec.js +++ b/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(); + }); }); diff --git a/src/core/Env.js b/src/core/Env.js index fc2fd27f..48146ac6 100644 --- a/src/core/Env.js +++ b/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); };