Skip to content

Commit

Permalink
fix(tests): stub focus-trap to fix webview tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Feb 20, 2025
1 parent 2b839a9 commit 826ac97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ignores:
- ts-loader
- mongodb-runner
- tabbable # Mocha register testing workaround stub.
- focus-trap # Mocha register testing workaround stub.
- ejson-shell-parser # Used by the connection-form.
18 changes: 17 additions & 1 deletion src/test/setup-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chai.use(sinonChai);
import { JSDOM, VirtualConsole } from 'jsdom';

/**
* NB: tabbable requires special overrides to work in jsdom environments as per
* NB: focus-trap and tabbable require special overrides to work in jsdom environments as per
* documentation
*
* @see {@link https://github.com/focus-trap/tabbable?tab=readme-ov-file#testing-in-jsdom}
Expand All @@ -28,6 +28,22 @@ Object.assign(tabbable, {
origTabbable.isTabbable(node, { ...options, displayCheck: 'none' }),
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
const focusTrap = require('focus-trap');

Object.assign(focusTrap, {
...focusTrap,
createFocusTrap: () => {
const trap = {
activate: (): unknown => trap,
deactivate: (): unknown => trap,
pause: (): void => {},
unpause: (): void => {},
};
return trap;
},
});

const virtualConsole = new VirtualConsole();
virtualConsole.sendTo(console, { omitJSDOMErrors: true });
virtualConsole.on('jsdomError', (err) => {
Expand Down

0 comments on commit 826ac97

Please sign in to comment.