Skip to content

Commit

Permalink
fix first event tracking property
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Hartz committed Nov 26, 2020
1 parent ae9fafa commit 2da2745
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions __tests__/useSwipeable.spec.tsx
Expand Up @@ -181,6 +181,29 @@ describe("useSwipeable", () => {
);
});

it("correctly tracks the first event", () => {
const onSwiping = jest.fn();
const { getByText } = render(<SwipeableUsingHook onSwiping={onSwiping} />);

const touchArea = getByText(TESTING_TEXT);

fireEvent[TS](touchArea, cte({ x: 100, y: 100 }));
fireEvent[TM](touchArea, cte({ x: 100, y: 125 }));
fireEvent[TM](touchArea, cte({ x: 100, y: 150 }));
fireEvent[TM](touchArea, cte({ x: 100, y: 175 }));
fireEvent[TE](touchArea, cte({}));

expect(onSwiping.mock.calls[0][0]).toEqual(
expect.objectContaining({ first: true })
);
expect(onSwiping.mock.calls[1][0]).toEqual(
expect.objectContaining({ first: false })
);
expect(onSwiping.mock.calls[2][0]).toEqual(
expect.objectContaining({ first: false })
);
});

it("calls preventDefault when swiping in direction that has a callback", () => {
const onSwipedDown = jest.fn();

Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -166,10 +166,11 @@ function getHandlers(
)
event.preventDefault();

// first is now always false
return {
...state,
eventData: { ...eventData, first: false },
// first is now always false
first: false,
eventData,
swiping: true,
};
});
Expand Down

0 comments on commit 2da2745

Please sign in to comment.