Spying on browser.notifications.create fails with "attempted to wrap undefined property..."
GrayedFox opened this issue · comments
Hello, the following code errors with "TypeError: attempted to wrap undefined property create as function" even though create is a valid and defined method of the notifications API.
const sinon = require('sinon')
const browser = require('sinon-chrome/extensions')
const chrome = require('sinon-chrome')
const { assert } = require('chai')
describe('hello', function () {
before(async function () {
global.browser = browser // need to patch global browser with mocked api
browser.menus = chrome.contextMenus // sinon-chrome doesn't wrap this method as it should
sinon.stub(browser.i18n, 'getAcceptLanguages').yields(['de-de', 'en-au'])
sinon.stub(browser.i18n, 'getUILanguage').yields('en-en')
sinon.spy(browser.menus, 'create')
sinon.spy(browser.notifications, 'create')
})
})
Both the menus and notifications spies fail with the same type error.
Am I doing something wrong here?
I debugged the notification and menu objects and realised that the create method is technically a getter.
Changing sinon.spy(browser.menus, 'create')
to sinon.spy(browser.menus, 'create', ['get'])
solved it, as per the Sinon getter spy/mock syntax.