Check that escape item is non-null before checking id
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 4 Apr 2017 20:12:29 +0000 (13:12 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 4 Apr 2017 20:12:29 +0000 (13:12 -0700)
lib/browser/api/touch-bar.js
spec/api-touch-bar-spec.js

index f9629a6..327b639 100644 (file)
@@ -101,7 +101,7 @@ class TouchBar extends EventEmitter {
 
     const interactionListener = (event, itemID, details) => {
       let item = this.items[itemID]
-      if (item == null && this.escapeItem.id === itemID) {
+      if (item == null && this.escapeItem != null && this.escapeItem.id === itemID) {
         item = this.escapeItem
       }
       if (item != null && item.onInteraction != null) {
index c2d5d26..7080304 100644 (file)
@@ -78,5 +78,17 @@ describe('TouchBar module', function () {
       window.setTouchBar(new TouchBar([new TouchBarLabel({label: 'two'})]))
       touchBar.escapeItem = null
     })
+
+    it('calls the callback on the items when a window interaction event fires', function (done) {
+      const button = new TouchBarButton({
+        label: 'bar',
+        click: () => {
+          done()
+        }
+      })
+      const touchBar = new TouchBar({items: [button]})
+      window.setTouchBar(touchBar)
+      window.emit('-touch-bar-interaction', {}, button.id)
+    })
   })
 })