diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index da5ff57a113f..e246a0894785 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -47,6 +47,9 @@ Menu.prototype._init = function () { } Menu.prototype.popup = function (options) { + if (options == null || typeof options !== 'object') { + throw new TypeError('Options must be an object') + } let {window, x, y, positioningItem, callback} = options // no callback passed diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index eb8fe3d63b2f..9aff30beeb6b 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -309,6 +309,12 @@ describe('Menu module', () => { return closeWindow(w).then(() => { w = null }) }) + it('throws an error if options is not an object', () => { + assert.throws(() => { + menu.popup() + }, /Options must be an object/) + }) + it('should emit menu-will-show event', (done) => { menu.on('menu-will-show', () => { done() }) menu.popup({window: w})