Merge pull request #11055 from electron/fix-menu-bug

fix: Don't crash on `setApplicationMenu(null)`
This commit is contained in:
Samuel Attard 2017-11-11 14:33:18 +11:00 committed by GitHub
commit ba754cf5c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -133,7 +133,7 @@ Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
// set application menu with a preexisting menu // set application menu with a preexisting menu
Menu.setApplicationMenu = function (menu) { Menu.setApplicationMenu = function (menu) {
if (!(menu || menu.constructor === Menu)) { if (menu && menu.constructor !== Menu) {
throw new TypeError('Invalid menu') throw new TypeError('Invalid menu')
} }

View file

@ -291,6 +291,7 @@ describe('Menu module', () => {
}) })
describe('Menu.setApplicationMenu', () => { describe('Menu.setApplicationMenu', () => {
it('sets a menu', () => {
const menu = Menu.buildFromTemplate([ const menu = Menu.buildFromTemplate([
{ {
label: '1' label: '1'
@ -302,6 +303,12 @@ describe('Menu module', () => {
assert.notEqual(Menu.getApplicationMenu(), null) assert.notEqual(Menu.getApplicationMenu(), null)
}) })
it('unsets a menu with null', () => {
Menu.setApplicationMenu(null)
assert.equal(Menu.getApplicationMenu(), null)
})
})
describe('MenuItem.click', () => { describe('MenuItem.click', () => {
it('should be called with the item object passed', function (done) { it('should be called with the item object passed', function (done) {
const menu = Menu.buildFromTemplate([ const menu = Menu.buildFromTemplate([