0

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.

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73

1 Answers1

0

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.

kb.
  • 1,955
  • 16
  • 22
  • I have tried the first one before. Tried the other one as well. In both cases i tried add requirejs into the dependencies and add the require statements. Still i get an error saying Can't find variable: require.Can you tell me the correct way of including the require module? – Pradeep Keshavprakash Jul 18 '16 at 09:13
  • another problem is i do not want to write tests to return promises. The Promise object is returned from the method i'm testing. – Pradeep Keshavprakash Jul 18 '16 at 09:16
  • @PradeepKeshavprakash It's a bit too broad of a question without seeing your specific implementation, I suggest you open a separate question for that showing some example code as well to reproduce the error. – kb. Jul 18 '16 at 09:19
  • no...i need to just know for any testing framework...how can i include requirejs properly to use it for including the libraries/plugins which u mentioned in ur first answer. – Pradeep Keshavprakash Jul 18 '16 at 09:41
  • Without knowing what you've tried there is not much I can suggest, I don't use it myself. There is a ticket on the mocha-phantomjs repo, https://github.com/nathanboktae/mocha-phantomjs/issues/80 that suggests ways to enable access to *require* in your tests. Even though the ticket itself is old (and refers to Node as well) it could be applicable to your situation as well. – kb. Jul 18 '16 at 09:59