Check menu.popup options are an object (#12325)

* check menu.popup options are an object

* Add a spec for menu.popup options check

* remove stray .only
This commit is contained in:
Shelley Vohr 2018-03-17 06:31:10 +09:00 committed by GitHub
parent 792837bd71
commit 31d688ad3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -47,6 +47,9 @@ Menu.prototype._init = function () {
} }
Menu.prototype.popup = function (options) { 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 let {window, x, y, positioningItem, callback} = options
// no callback passed // no callback passed

View file

@ -309,6 +309,12 @@ describe('Menu module', () => {
return closeWindow(w).then(() => { w = null }) 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) => { it('should emit menu-will-show event', (done) => {
menu.on('menu-will-show', () => { done() }) menu.on('menu-will-show', () => { done() })
menu.popup({window: w}) menu.popup({window: w})