NodeJS, WebStorm and Jasmine: ReferenceError: describe is not defined when debugging
Solution 1
You are using Node.js run configuration to run your tests - and Node knows nothing about your test framework. You should be using a test runner (karma, for example - as you have karma installed). Try using karma run configuration. See https://confluence.jetbrains.com/display/WI/Running+JavaScript+tests+with+Karma.
BTW, if you like using Should with karma, try karma-should
Solution 2
Try using jasmine-node
module.
It depends on the command send to the js file when you press F5. It needs to be jasmine-node <test files>
not node <test files>
.
Try doing that in the console/terminal and see if it works. It could be web storm sending the wrong command.
If you haven't got jasmine node installed you can do
npm install jasmine-node -g
brimble2010
Updated on June 05, 2022Comments
-
brimble2010 almost 2 years
I'm trying to debug some Jasmine tests that I have written using WebStorm 2016.1.2.
My test code looks like this:
var should = require("should"); var myLib = require("../my-lib"); describe("Scenario", () => { it("works as expected", () => { myLib.do().should.not.throw() }); });
My directory structure looks like this:
│ ├───node_modules │ ├───.bin │ ├───aws-sdk │ │ └───<snip> │ ├───jasmine │ │ └───<snip> │ ├───jasmine-core │ │ └───<snip> │ ├───karma │ │ └───<snip> │ ├───karma-jasmine │ │ └───<snip> │ ├───should │ │ └───<snip> │ └───sinon │ └───<snip> ├───spec │ ├───support │ │ └───jasmine.json │ └───my-lib.spec.js └───my-lib.js
And my NodeJS settings in WebStorm look like this:
To debug I'm just hitting F5 and choosing the
my-lib.spec.js
file to run. I Then get the following stack trace:"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.2\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=22714 my-lib.spec.js Debugger listening on port 22714 c:\Users\<me>\WebstormProjects\my-lib\spec\my-lib.spec.js:4 describe("Scenario", () => { ^ ReferenceError: describe is not defined at Object.<anonymous> (c:\Users\<me>\WebstormProjects\my-lib\spec\<my-lib>.js:4:1) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.runMain [as _onTimeout] (module.js:442:10) at Timer.listOnTimeout (timers.js:92:15) Process finished with exit code 1
If anyone knows how to make WebStorm recognise that Jasmine is installed globally that'd be great.
EDIT: I've set up a Karma run configuration as suggested by lena with the following configuration:
When I hit F5 to run this, a Chrome browser pops up and is blank (I have the JetBrains plugin for Chrome installed)
-
brimble2010 almost 8 years
jasmine-node
hasn't been updated in a long time and doesn't support the latest version of Jasmine.