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!
Aucun commentaire:
Enregistrer un commentaire