testBeforeShowEvent() {
    popup.render();
    /** @suppress {visibility} suppression added to enable type checking */
    const target = popup.createAttachTarget(anchor);
    popup.attach(anchor);

    function beforeShowPopup(e) {
      // Ensure that the element is not yet visible.
      assertFalse(
          'The element should not be shown when BEFORE_SHOW event is ' +
              'being handled',
          style.isElementShown(popup.getElement()));
      // Verify that current anchor is set before dispatching BEFORE_SHOW.
      assertNotNullNorUndefined(popup.getAttachedElement());
      assertEquals(
          'The attached anchor element is incorrect', target.element_,
          popup.getAttachedElement());
      beforeShowPopupCalled = true;
      return showPopup;
    }
    function onShowPopup(e) {
      assertEquals(
          'The attached anchor element is incorrect', target.element_,
          popup.getAttachedElement());
    }

    handler.listen(popup, Menu.EventType.BEFORE_SHOW, beforeShowPopup);
    handler.listen(popup, Menu.EventType.SHOW, onShowPopup);

    beforeShowPopupCalled = false;
    showPopup = false;
    popup.showMenu(target, 0, 0);
    assertTrue(
        'BEFORE_SHOW event handler should be called on #showMenu',
        beforeShowPopupCalled);
    assertFalse(
        'The element should not be shown when BEFORE_SHOW handler ' +
            'returned false',
        style.isElementShown(popup.getElement()));

    beforeShowPopupCalled = false;
    showPopup = true;
    popup.showMenu(target, 0, 0);
    assertTrue(
        'The element should be shown when BEFORE_SHOW handler ' +
            'returned true',
        style.isElementShown(popup.getElement()));
  }
Test menu receives BEFORE_SHOW event before it's displayed.
     @suppress {visibility} suppression added to enable type checking