Skip to content

Commit

Permalink
fix(rtl): fix noPolyfill arg in scrollToItem
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Jan 29, 2024
1 parent e2fedec commit 3fdaef3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
]
},
"test:lint": {
"command": "tsc --noEmit && eslint src"
"command": "eslint src && tsc --noEmit"
},
"test:unit": {
"command": "jest",
Expand Down
34 changes: 34 additions & 0 deletions src/createApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const setup = (ratio = [0.3, 1, 0.7]) => {
describe('createApi', () => {
afterEach(() => {
jest.clearAllMocks();
jest.restoreAllMocks();
});

test('visibleElementsWithSeparators', () => {
Expand Down Expand Up @@ -130,6 +131,39 @@ describe('createApi', () => {
});
});

test('with noPolyfill', () => {
const { items, visibleElementsWithSeparators } = setup([0.7, 0, 0]);
const scrollToItemSpy = jest
.spyOn(helpers, 'scrollToItem')
.mockReturnValue(jest.fn());

const boundary = { current: document.createElement('div') };
const transitionOptions = undefined;

const noPolyfill = true;

const elem = document.createElement('div');
createApi(
items,
visibleElementsWithSeparators,
boundary,
transitionOptions,
undefined,
noPolyfill
).scrollToItem(elem);

expect(scrollToItemSpy).toHaveBeenCalledTimes(1);
expect(scrollToItemSpy).toHaveBeenNthCalledWith(
1,
elem,
undefined,
undefined,
undefined,
expect.objectContaining({ boundary: expect.anything() }),
noPolyfill
);
});

test('arguments should have priority over transitionOptions', () => {
const { items, visibleElementsWithSeparators } = setup([0.7, 0, 0]);

Expand Down
19 changes: 13 additions & 6 deletions src/createApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ export default function createApi(
options?: scrollToItemOptions
) => {
const _behavior = behavior ?? transitionOptions?.behavior;
return scrollToItem(target, _behavior, inline, block, {
boundary: boundaryElement?.current,
...options,
duration: options?.duration ?? transitionOptions?.duration,
ease: options?.ease ?? transitionOptions?.ease,
});
return scrollToItem(
target,
_behavior,
inline,
block,
{
boundary: boundaryElement?.current,
...options,
duration: options?.duration ?? transitionOptions?.duration,
ease: options?.ease ?? transitionOptions?.ease,
},
noPolyfill
);
},
visibleElements,
visibleElementsWithSeparators,
Expand Down

0 comments on commit 3fdaef3

Please sign in to comment.