Paul Chernoch Paul Chernoch - 3 months ago 24
Javascript Question

Test if a promise is resolved or rejected with Jasmine 1.3 in Nodejs

I am using the npm library jasmine-node for unit testing of my javascript code. As far as I understand, it uses Jasmine 1.3.

Most of my code involves asynchronous Promises (using ES6 built-in promises, not one of the 3rd party Promise libraries). I have read that Jasmine 2 has a method called done() that you can call from the "then" or "catch" call on your promise. What can I do in Jasmine 1.3? Is there a way to simulate this? Or is there a better approach or different branch of jasmine-node?

See this question:
Test if a promise is resolved or rejected with Jasmine in Nodejs


You should avoid using the jasmine-node module. It is no longer maintained (last commit was over two years ago, and the PRs are piling up). Instead you should be using jasmine-core, the official bundling of jasmine.

And honestly, the bundlings of these packages is not too clear. You actually want to install the jasmine package. This provides you with command line tools that help you provision a project for use with jasmine and gives you commands to run the specs. Eg (from the documentation):

Local installation:

npm install --save-dev jasmine

To initialize a project for Jasmine

./node_modules/.bin/jasmine init

To seed your project with some examples

./node_modules/.bin/jasmine examples

To run your test suite


You can also choose to install jasmine globally like this:

npm install -g jasmine

This way, you can avoid prefixing each invocation with ./node_modules/.bin/. But, I prefer using a locally installed instance for all project dependencies. This ensures that you use the same version of dependencies that your project expects.