Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Worker not defined when I try to run mocha test

I want to write test script to check whether Worker gets created in a function in some external file. The function I want to test is,

createPoller: function () {
  var poller = new Worker(POLLER_PATH),
      _this = this;


  /* worker handler on receiving the message */
  poller.onmessage = this.handlePoller.bind(_this);
  this.set('pollerId', U.generateUUID());
  this.set('poller', poller);
}
>>> ReferenceError: Worker is not defined
at new Worker(POLLER_PATH)
      ^

When I run the code, workers are created and they work fine. But when I run script on that particular code it says Worker is undefined.

like image 560
Saba Hassan Avatar asked Oct 31 '22 07:10

Saba Hassan


1 Answers

If the JavaScript environment you use supports web workers natively, then they should just be there for you to use, and your code should work. So the most probable issue is that you are in fact running your code in a JavaScript environment that does not support web workers natively. If you want to use web workers in Node.js, for instance, you'd have to add a library that provides it. According to MDN, IE does not support web workers before version 10.

like image 55
Louis Avatar answered Nov 15 '22 04:11

Louis