45

If I recall there is a command in Jasmine that will log the exact version of Jasmine I'm running to the console, but I can't remember what it is. I am positive I have seen this before somewhere, and now that I actually need it I can't find it anywhere. Does anyone know what it is?


Edit: The posted solution of using jasmine.getEnv().versionString() isn't working - to any mods reading this, would fixing that issue be better to start as a new question, or continue here?

TheGuyWithTheFace
  • 2,615
  • 3
  • 13
  • 16

5 Answers5

53

command line command:

Detailed view:

npm view jasmine

or

Version Number:

npm view jasmine version
David Makogon
  • 69,407
  • 21
  • 141
  • 189
Mike Stahl
  • 531
  • 4
  • 2
52

To simply log the version number try:

   if (jasmine.version) { //the case for version 2.0.0
       console.log('jasmine-version:' + jasmine.version);
    }
    else { //the case for version 1.3
       console.log('jasmine-version:' + jasmine.getEnv().versionString());
    }

I use this little helper function:

 this.isJasmineV2 = function () {
        return (jasmine.version && jasmine.version.charAt(0) === "2");
        //version 1.3 uses this syntax: jasmine.getEnv().versionString()
    };
Mike
  • 2,399
  • 1
  • 20
  • 26
4
describe('Test to print out jasmine version', function() {
it('prints jasmine version', function() {
        console.log('jasmine-version:' + jasmine.getEnv().versionString());
    });
});

Source: Updating the version of Jasmine used in karma-jasmine

Community
  • 1
  • 1
Vincent Vance
  • 117
  • 1
  • 4
  • 13
  • That looks like what I need, but when I run it I get an error: `'undefined' is not a function (evaluating 'jasmine.getEnv().versionString()') `. Any thoughts? – TheGuyWithTheFace Jul 09 '14 at 15:47
  • 1
    Try with this line instead `console.log(jasmine.version || (jasmine.getEnv().versionString && jasmine.getEnv().versionString()));` – josketres Jul 17 '15 at 12:52
3

Judging by the code

jasmine.version

should give you the version string.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
1

Do above mentioned or simply go to jasmine.js file and look for function getJasmineRequireObj().version. This function is returning the version of the jasmine.

  • 1
    Thank you. I found it in `node_modules/jasmine-core/lib/jasmine-core/jasmine.js`: `getJasmineRequireObj().version = function() { return '3.5.0'; };` – JohnK Jan 20 '20 at 16:34