function mockFocusVisible(focusableEl, { phase, hasKeyboardInteraction }) {
  const focusVisibleApplies = phase === 'focusin' && hasKeyboardInteraction;
  if (!focusVisibleApplies) {
    return () => {};
  }

  /** @type {any} */
  const originalMatches = focusableEl.matches;
  if (typeof windowWithOptionalPolyfill.applyFocusVisiblePolyfill !== 'function') {
    // eslint-disable-next-line no-param-reassign
    focusableEl.matches = selector =>
      selector === ':focus-visible' || originalMatches.call(focusableEl, selector);
    return () => {
      // eslint-disable-next-line no-param-reassign
      focusableEl.matches = originalMatches;
    };
  }

  const originalHasAttribute = focusableEl.hasAttribute;
  // eslint-disable-next-line no-param-reassign
  focusableEl.hasAttribute = attr =>
    attr === 'data-focus-visible-added' || originalHasAttribute.call(focusableEl, attr);
  return () => {
    // eslint-disable-next-line no-param-reassign
    focusableEl.hasAttribute = originalHasAttribute;
  };
}
Checks two things:
1. whether focus-visible should apply (if focus and keyboard interaction present)
2. whether the polyfill is used or not
When the polyfill is used, it mocks `.hasAttribute` method, otherwise `.matches` method
of focusable element.
@param {HTMLElement} focusableEl focusable element
@param {{phase: 'focusin'|'focusout', hasKeyboardInteraction: boolean }} options
@returns {function} restore function