From a7052efaf4fc6bb2aeedd6579e662e98aa2237dd Mon Sep 17 00:00:00 2001 From: Dominic <8808097+doms@users.noreply.github.com> Date: Wed, 8 Aug 2018 15:38:52 -0700 Subject: [PATCH] fix: make menu.popup options optional (#13977) * add empty object as default param for options * update docs * add spec for optional options * fix: add null check for options --- docs/api/menu.md | 2 +- lib/browser/api/menu.js | 2 +- spec/api-menu-spec.js | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/api/menu.md b/docs/api/menu.md index 339a9ef7986b..e1d6e9958de7 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -61,7 +61,7 @@ The `menu` object has the following instance methods: #### `menu.popup(options)` -* `options` Object +* `options` Object (optional) * `window` [BrowserWindow](browser-window.md) (optional) - Default is the focused window. * `x` Number (optional) - Default is the current mouse cursor position. Must be declared if `y` is declared. diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index dcc446587913..c0cc199e05a8 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -47,7 +47,7 @@ Menu.prototype._init = function () { this.delegate = delegate } -Menu.prototype.popup = function (options) { +Menu.prototype.popup = function (options = {}) { if (options == null || typeof options !== 'object') { throw new TypeError('Options must be an object') } diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 99b0f3cf34c5..e4566dba43a8 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -633,10 +633,16 @@ describe('Menu module', () => { it('throws an error if options is not an object', () => { expect(() => { - menu.popup() + menu.popup('this is a string, not an object') }).to.throw(/Options must be an object/) }) + it('allows for options to be optional', () => { + expect(() => { + menu.popup({}) + }).to.not.throw() + }) + it('should emit menu-will-show event', (done) => { menu.on('menu-will-show', () => { done() }) menu.popup({window: w})