8000 fix: make menu.popup options optional by doms · Pull Request #13977 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: make menu.popup options optional #13977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
8 changes: 7 additions & 1 deletion spec/api-menu-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃

}).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})
Expand Down
0