Skip to content

Commit

Permalink
add tabbable mock for focus trap
Browse files Browse the repository at this point in the history
  • Loading branch information
NFriedo committed Dec 13, 2024
1 parent 386a5bb commit 551a595
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ config.global.renderStubDefaultSlot = true;
global.mount = mount;
global.shallowMount = shallowMount;

/**
* mock needed for useFocusTrap in combination with jsdom
* this resolves the error "Your focus-trap must have at least one container with at least one tabbable node in it at all times"
* @see https://github.com/focus-trap/tabbable?tab=readme-ov-file#testing-in-jsdom
*/
jest.mock("tabbable", () => {
const lib = jest.requireActual("tabbable");
return {
...lib,
tabbable: (node, options) =>
lib.tabbable(node, { ...options, displayCheck: "none" }),
focusable: (node, options) =>
lib.focusable(node, { ...options, displayCheck: "none" }),
isFocusable: (node, options) =>
lib.isFocusable(node, { ...options, displayCheck: "none" }),
isTabbable: (node, options) =>
lib.isTabbable(node, { ...options, displayCheck: "none" }),
};
});

/**
* matchMedia is used by
* - useBreakpoints from VueUse to distinguish breakpoints
Expand Down

0 comments on commit 551a595

Please sign in to comment.