Merge pull request #6184 from electron/read-only-command-id

Make MenuItem.commandId read only
This commit is contained in:
Kevin Sawicki 2016-06-22 13:09:16 -07:00 committed by GitHub
commit 56b3478760
2 changed files with 16 additions and 3 deletions

View file

@ -72,7 +72,7 @@ const MenuItem = function (options) {
throw new Error(`Unknown menu item type: ${this.type}`)
}
this.commandId = ++nextCommandId
this.overrideReadOnlyProperty('commandId', ++nextCommandId)
const click = options.click
this.click = (event, focusedWindow) => {

View file

@ -357,10 +357,23 @@ describe('menu module', function () {
})
})
describe('MenuItem command id', function () {
it('cannot be overwritten', function () {
var item = new MenuItem({
label: 'item'
})
var commandId = item.commandId
assert(commandId != null)
item.commandId = '' + commandId + '-modified'
assert.equal(item.commandId, commandId)
})
})
describe('MenuItem with invalid type', function () {
it('throws an exception', function () {
assert.throws(function () {
var menu = Menu.buildFromTemplate([
Menu.buildFromTemplate([
{
label: 'text',
type: 'not-a-type'
@ -373,7 +386,7 @@ describe('menu module', function () {
describe('MenuItem with submenu type and missing submenu', function () {
it('throws an exception', function () {
assert.throws(function () {
var menu = Menu.buildFromTemplate([
Menu.buildFromTemplate([
{
label: 'text',
type: 'submenu'