acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
435 stars 46 forks source link

Chrome Application runtime #53

Closed sagorshkov closed 7 years ago

sagorshkov commented 7 years ago

Hello. I'm using your awesome module to mock chrome application object in my tests and I've got an issue. Method chrome.runtime.getManifest() returns undefined, but there is something like this in my code: chrome.runtime.getManifest().version. I've tried to redefine getManifest method but It's not possible because of the descriptor of this property is:

Object.getOwnPropertyDescriptor(chrome.runtime, 'getManifest') Object {set: undefined, enumerable: false, configurable: false, get: function} configurable:false enumerable:false get:function get() set:undefined __proto__:Object

Is there a way to compel getManifest() return some objects? Thanks in advance.

acvetkov commented 7 years ago

@sagorshkov hi!

You should not redefine getManifest, it's already sinon stub without predefined behavior. Just define returning value

chrome.runtime.getManifest.returns({
   version: '0.0.1',
   // other important props
});
sagorshkov commented 7 years ago

Awesome! Thank you.