A set of tools for emulating browser behavior in jsdom environment
Thanks @davidr64 for the contribution!
Test support for @swc/jest
Removes dependencies on window
during import. Thank you @sbaechler!
configMocks
jest
configMocks
Added missing support for steps
easing in the WAAPI implementation
Thanks to @adjsky there's less bugs in the Animation API mock 🎉
Fixes:
element.animate
will now correctly accept the id
optionPotentially it can break your code if you were relying on the current behaviour.
An attempt to get a little bit closer to the ResizeObserver spec.
There are no breaking changes (as far as I see), the old code should still work. However there's a small change in philosophy, so here's a recommended migration guide:
mockElementSize
) instead of mockElementBoundingClientRect
Before:
import { mockResizeObserver, mockElementBoundingClientRect } from 'jsdom-testing-mocks';
const resizeObserver = mockResizeObserver();
it('works', () => {
render(<TestedComponent />);
const element = screen.getBySomething(...)
// tests...
mockElementBoundingClientRect(element, {
width: 300, height: 200,
});
act(() => {
resizeObserver.resize(element);
});
// tests...
})
After:
import { mockResizeObserver } from 'jsdom-testing-mocks';
const resizeObserver = mockResizeObserver();
it('works', () => {
render(<TestedComponent />);
const element = screen.getBySomething(...)
// tests...
resizeObserver.mockElementSize(element, {
contentBoxSize: { inlineSize: 300, blockSize: 200 },
});
act(() => {
resizeObserver.resize(element);
});
// tests...
})
.resize
function, it will be triggered automatically (if the size is mocked)PS. Check the new docs for more details