1

I've never really worked with npm, jasmine and node for that matter. So the whole toolchain is a bit overwhelming. I ran into this today:

I want to add extend functionality to SIP.js for a PR I'm working on.

If I require('extend') like so:

module.exports = function (SIP) {

  var extend = require('extend');

  var UA,
  ...
  UA.prototype.isConnected = function() {
     return this.transport ? this.transport.connected : false;
  };
  ...
  UA.prototype.invite = function(target, options) {
    options = extend(true, {}, options) || {};

I assign the module.exported function from the extend package to a variable. Now my question is, how can I stub extend() in a jasmine spec?

spyOn(UA, 'isConnected').and.returnValue(true); // works ok, UA has 'isConnected' property
spyOn(WHATOBJECT?, 'extend').and.returnValue(extendedOptions);

I also tried assigning extend to UA property like so

module.exports = function (SIP) {

  var extend = require('extend');

  var UA,
  ...
  UA.extend = extend;

and in the spec:

spyOn(UA, 'extend')...

But still get an error when I run jasmine.

Error: extend() method does not exist in file:///Users/wpp/SIP.js/.grunt/grunt-contrib-jasmine/jasmine.js (line 1861) (1)

Is it some global object like window in the browser? Thanks for your help!

wpp
  • 7,093
  • 4
  • 33
  • 65
  • possible duplicate of [How to stub require() / expect calls to the "root" function of a module?](http://stackoverflow.com/questions/6997459/how-to-stub-require-expect-calls-to-the-root-function-of-a-module) – Paul Sweatte Jun 17 '15 at 08:57

0 Answers0