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
This commit is contained in:
parent
fc4499ebd4
commit
a7052efaf4
3 changed files with 9 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in a new issue