Jasmine 2, 'shared' beforeEach

I have Jasmine test code that ran OK under Jasmine 1.3 but is failing under Jasmine 2.0.

The tests are configured like this:

///<reference path="~/scripts/jasmine/tests/BaseReferences.js"/>

///<reference path="~/scripts/document/move.js"/>

describe("move", function () {

    beforeEach(function () {

    }
}))

BaseReferences.js contains all the helper JS that's common across the tests, in particular it contains 'SpecHelpers.js' which has a 'beforeEach' call in

It looks like that when SpecHelpers.js is loaded then Jasmine 2 has not been loaded and the call to beforeEach fails.

This works fine if loaded from the Jasmine html page (specRunner.html) and used to work when I used 1.3.

Is there any way to do this?

Thanks,

Kevin Jones
11 comments
Comment actions Permalink

Hi Kevin,

you may control the order of references in your test file. Just put all

///<reference path="~/scripts/jasmine/tests/BaseReferences.js"/>
///<reference path="~/scripts/document/move.js"/>

before

///<reference path="~/scripts/jasmine/jasmine.js"/>

PS Is this a duplicate of this thread: http://devnet.jetbrains.com/message/5512835#5512835

0
Comment actions Permalink

Thanks Victor - the duplicate is mine; I'd posted the question twice before it was accepted

I've tried adding the jasmine references (and boot.js) both before and after the spechelper.js reference and it doesn't work.

As I understand it though I don't need to reference the Jasmine files for the tests to run; the test runner adds them for me. The tests that don't rely on bits setup in my global beforeEach run fine (without references to the external Jasmine.js), while those that require my global beforeEach fail as this is not getting run,

Kevin

0
Comment actions Permalink

Reference to jasmine.js is not required, this is correct. But if you reference it manually, than you may change the order of references, e. g. put jasmine.js. By default, it is referenced first.

0
Comment actions Permalink

Thanks Victor,  but as I said this doesn't fix the issue.

You say that Jasmine is loaded first but the call to beforeEach in the JS file referenced before the tests run fails

0
Comment actions Permalink

Hi Kevin,

could you please share full example to reproduce this issue?

0
Comment actions Permalink

The default player/song tests that come with Jasmine 2 show this behaviour.

there's a beforeEach in the SpecHelper.js, that creates a 'toBePlaying' matcher.
If you run the tests 'as is' then this matcher is not created and the "should indicate that the song is currently paused" fails.

If you copy the 'toBePlaying' matcher into the test's beforeEach then the test passes,

Kevin

0
Comment actions Permalink

Fixed, thanks!
Fix will be available in 8.2.1 update soon.

0
Comment actions Permalink

We are having the same issue. We upgraded for jasmine 2.0 support. When will 8.2.1 be released?

0
Comment actions Permalink

No estimate at the moment, but soon.

0
Comment actions Permalink

I have 8.2.1 (8.2.1000.4556) installed.  My tests still hang.  Did the fix _not_ get in there?  Or maybe the change didn't fix all issues WRT beforeEach.

0

Please sign in to leave a comment.