Open vekunz opened 2 years ago
Since I do not think this bug will get fixed, I reverse-engineered the code of the MDCDialog and came up with a workaround for our unit tests.
First, you need a MockFocusTrap class.
class MockFocusTrap {
public trapFocus(): void {}
public releaseFocus(): void {}
}
Then you can set up this mock. We use Vitest, but it should work with other Tests Frameworks also.
vi.mock('@material/dom/focus-trap', () => ({
FocusTrap: MockFocusTrap
}));
Bug report
Background
We are working with MDC on a SvelteKit application. Because there is not a good Material library for Svelte, we create our own Svelte components with the MDC components. We are unit testing our Svelte MDC components with
vitest
,jsdom
, and@testing-library/svelte
. The Bug occurs while running the unit tests.Steps to reproduce
npm install
)npm run test
Actual behavior
The test fails with a focus trap error.
Expected behavior
Since the dialog contains a focusable element, there should not occur a focus trap error.
Your Environment:
Additional context
The HTML that is used by the tests looks like this.