Browse Source

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
Dominic 6 years ago
parent
commit
a7052efaf4
3 changed files with 9 additions and 3 deletions
  1. 1 1
      docs/api/menu.md
  2. 1 1
      lib/browser/api/menu.js
  3. 7 1
      spec/api-menu-spec.js

+ 1 - 1
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.

+ 1 - 1
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')
   }

+ 7 - 1
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})