How to test a javascript method which returns a Promise object using mocha-phantomjs

122 Views Asked by At

I have a couple of unit tests written in mocha which I'm able to run on the browser. I need to automate these tests on a server machine where I will be writing a CLI commands. The problem is when I try to run the tests using PhantomJS I get an error saying

ReferenceError: Can't find variable: Promise at file:///C:/Halosys/halosysus_jslibrary/dest/hmsdk.js:5061 at file:///C:/Halosys/halosysus_jslibrary/tests/ISession_Spec.js:29 at callFnAsync

(file:///C:/Halosys/halosysus_jslibrary/node_modules/mocha/mo cha.js:4506)

I'm confused on how to fix this error.

1

There are 1 best solutions below

5
kb. On

PhantomJS does not support promises, more information is available on the PhantomJS issue tracker (#12401).

You can try using the libraries es6-promise or promise-polyfill to augment the functionality for now.