import { renderHookWithProviders, fireEvent } from "testUtilities";
import useKeyboardEsc from "./index";
var addEventListener = document.addEventListener;
afterEach(function () {
  return document.addEventListener = addEventListener;
});
it("renders", function () {
  document.addEventListener = jest.fn();
  var _renderHookWithProvid = renderHookWithProviders(function () {
      return useKeyboardEsc();
    }),
    result = _renderHookWithProvid.result;
  fireEvent.keyDown(document, {
    keyCode: 27
  });
  expect(result.error).toBeUndefined();
  expect(document.addEventListener).toHaveBeenCalledTimes(0);
});
it("triggers on enter keystroke", function () {
  var callback = jest.fn();
  renderHookWithProviders(function () {
    return useKeyboardEsc(callback);
  });
  fireEvent.keyDown(document, {
    keyCode: 27
  });
  expect(callback).toHaveBeenCalledTimes(1);
});
it("does not trigger on non enter keystroke", function () {
  var callback = jest.fn();
  renderHookWithProviders(function () {
    return useKeyboardEsc(callback);
  });
  fireEvent.keyDown(document, {
    keyCode: 26
  });
  expect(callback).toHaveBeenCalledTimes(0);
});