@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
27 lines (26 loc) • 979 B
JavaScript
import { describe, expect, it, vi } from 'vitest';
import { scrollToSlide } from './scrollToSlide';
describe('scrollToSlide', () => {
it('scrolls the scroller to the element offsetLeft', () => {
const scrollToMock = vi.fn();
const element = { offsetLeft: 42 };
const ref = {
current: { children: [element], scrollTo: scrollToMock },
};
scrollToSlide(0, ref);
expect(scrollToMock).toHaveBeenCalledWith({ left: 42 });
});
it('returns undefined if there is no scrollerElement', () => {
const ref = { current: null };
const result = scrollToSlide(0, ref);
expect(result).toBeUndefined();
});
it('returns undefined if there is no element', () => {
const scrollToMock = vi.fn();
const ref = {
current: { children: [], scrollTo: scrollToMock },
};
const result = scrollToSlide(0, ref);
expect(result).toBeUndefined();
});
});