From e34e440acd6a1820606db9e4625fc3a53e718448 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 24 Feb 2023 12:10:12 +0100 Subject: [PATCH] add style and focus-trap mocks for jest Signed-off-by: Maksim Sukharev --- jest.config.js | 4 ++++ src/__mocks__/styles.js | 1 + src/__mocks__/tabbable.js | 12 ++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 src/__mocks__/styles.js create mode 100644 src/__mocks__/tabbable.js diff --git a/jest.config.js b/jest.config.js index fde356dfda..db26783018 100644 --- a/jest.config.js +++ b/jest.config.js @@ -59,6 +59,10 @@ module.exports = { 'vue', ], + moduleNameMapper: { + '\\.(css|scss)$': '/src/__mocks__/styles.js', + }, + transform: { // process `*.js` files with `babel-jest` '.*\\.(js)$': 'babel-jest', diff --git a/src/__mocks__/styles.js b/src/__mocks__/styles.js new file mode 100644 index 0000000000..4ba52ba2c8 --- /dev/null +++ b/src/__mocks__/styles.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/src/__mocks__/tabbable.js b/src/__mocks__/tabbable.js new file mode 100644 index 0000000000..c7d1bc1541 --- /dev/null +++ b/src/__mocks__/tabbable.js @@ -0,0 +1,12 @@ +// https://github.com/focus-trap/tabbable#testing-in-jsdom +const lib = jest.requireActual('tabbable') + +const tabbable = { + ...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' }), +} + +module.exports = tabbable