36

Questions

Background

I've installed Karma and karma-jasmine using Yeoman as follows:

$ npm install -g generator-angular
$ mkdir myapp && cd $_
$ yo angular

Given that myapp/bower.json didn't list Jasmine as one of the Bower installed front-end packages but myapp/karma.conf.js listed Jasmine as the default testing framework, I was surprised the command grunt test worked. (The Gruntfile.js, bower.json, and karma.conf.js files were all created as part of the yo angular scaffolding process.)

Upon closer inspection of the myapp/node_modules packages, I realized that karma-jasmine doesn't point to a separate installation of Jasmine. The karma-jasmine plugin actually installs Jasmine:

▼ myapp/
  ▼ karma_jasmine/
    ▼ lib/
        adapter.js
        index.js
        jasmine.js

Given that karma-jasmine says it is an "adapter for the Jasmine testing framework," I was a little surprised that karma-jasmine didn't require us to install Jasmine separately.

Package Versions

Here are the various package versions used:

  • Karma: "~0.10.8" per myapp/package.json contents
  • karma-jasmine: "~0.1.4" per myapp/package.json contents
  • Yeoman: "1.0.6" per npm list -g | grep yo command results
  • Jasmine: Unknown but based on a few diffs, I'm almost wondering if karma-jasmine includes a customized version of Jasmine to work with Karma.
Community
  • 1
  • 1
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163

2 Answers2

30

You can know the jasmine version you are using by running the following Spec:

describe('Test to print out jasmine version', function() {
  it('prints jasmine version', function() {
    console.log('jasmine-version:');
    console.log(jasmine.version || (jasmine.getEnv().versionString && jasmine.getEnv().versionString()));
  });
});

and then checking the karma output in your console or browser. It should be something like:

LOG: 'jasmine-version:'
LOG: '2.3.4'

The jasmine library is included in the jasmine-runner plugin as you've already found out. You can find the exact place where this file is loaded in the source code of the plugin: https://github.com/karma-runner/karma-jasmine/blob/master/lib/index.js (line 7)

You can try to modify the plugin so that an upgrade is possible and send a pull request to karma (see http://karma-runner.github.io/0.10/dev/contributing.html)

josketres
  • 3,329
  • 1
  • 26
  • 23
  • 2
    looks like there is a pending PR for karma-jasmine 2.0 update: https://github.com/karma-runner/karma-jasmine/pull/18; and as referenced there, for folks using angular also: https://github.com/angular/angular.js/pull/5662 – ossek Feb 03 '14 at 01:45
  • 1
    ...and currentSpec is changed to work for Jasmine 2 in the new release (1.2.11)! https://github.com/angular/angular.js/blob/master/CHANGELOG.md. – ossek Feb 03 '14 at 23:01
  • 1
    The syntax to print the version number seems to differ between v1.3 and v2.0. See: http://stackoverflow.com/questions/24658007/how-can-i-confirm-what-version-of-jasmine-im-using/24919927#24919927 – Mike Jul 23 '14 at 20:07
  • I have updated Karma-Jasmine to 0.3.8 (latest) version but when I try to run the code snippet above to find out the jasmine-core version... it still shows 1.3.1 – Rogério Peixoto Apr 26 '16 at 13:07
13

It a better option to stick to the jasmine version in karma-jasmine and update the whole package. You can use the following command to get the version of all the installed packages:

  npm ls

To get the version of the installed global packages:

  npm ls -g

To view the latest version available on CDN, use:

  npm view karma-jasmine version

Before updating, you can view all versions at the CDN using:

  npm view karma-jasmine versions

To install a specific version:

  npm install karma-jasmine@~0.2.2 

(0.2.2 is the latest available).

AliR
  • 2,065
  • 1
  • 27
  • 37
  • This is wrong: `npm view version` tells you what the _published_ package.json of says (i.e., what's in the registry), not what you have installed on your machine. See http://stackoverflow.com/questions/10972176/find-the-version-of-an-installed-npm-package – Ted M. Young Mar 24 '15 at 21:59
  • The point of the OP was to determine the version of Jasmine, not the version of the karma-jasmine adapter. They are two very different things. – gravidThoughts Jun 04 '15 at 16:26