Skip to content

Commit a7052ef

Browse files
domsckerr
authored andcommitted
fix: make menu.popup options optional (electron#13977)
* add empty object as default param for options * update docs * add spec for optional options * fix: add null check for options
1 parent fc4499e commit a7052ef

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

docs/api/menu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The `menu` object has the following instance methods:
6161

6262
#### `menu.popup(options)`
6363

64-
* `options` Object
64+
* `options` Object (optional)
6565
* `window` [BrowserWindow](browser-window.md) (optional) - Default is the focused window.
6666
* `x` Number (optional) - Default is the current mouse cursor position.
6767
Must be declared if `y` is declared.

lib/browser/api/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Menu.prototype._init = function () {
4747
this.delegate = delegate
4848
}
4949

50-
Menu.prototype.popup = function (options) {
50+
Menu.prototype.popup = function (options = {}) {
5151
if (options == null || typeof options !== 'object') {
5252
throw new TypeError('Options must be an object')
5353
}

spec/api-menu-spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,16 @@ describe('Menu module', () => {
633633

634634
it('throws an error if options is not an object', () => {
635635
expect(() => {
636-
menu.popup()
636+
menu.popup('this is a string, not an object')
637637
}).to.throw(/Options must be an object/)
638638
})
639639

640+
it('allows for options to be optional', () => {
641+
expect(() => {
642+
menu.popup({})
643+
}).to.not.throw()
644+
})
645+
640646
it('should emit menu-will-show event', (done) => {
641647
menu.on('menu-will-show', () => { done() })
642648
menu.popup({window: w})

0 commit comments

Comments
 (0)