Skip to content

Commit

Permalink
test(useVisibility): add functional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Aug 8, 2021
1 parent 508506c commit 8d41f61
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/hooks/useVisibility.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fireEvent, render } from '@testing-library/react';
import React, { useRef } from 'react';
import useVisibility from './useVisibility';

const Header = (): JSX.Element => {
const headerRef = useRef<HTMLDivElement>(null);
const onBottomPassed = jest.fn();
const onBottomPassedReverse = jest.fn();

useVisibility({
ref: headerRef,
onBottomPassed,
onBottomPassedReverse,
});

return (
<div
ref={headerRef}
style={{ display: 'block', width: '100%', height: '100vh' }}
>
App
</div>
);
};

describe('useVisibility', () => {
test('should work correctly when scrolling and resizing', () => {
const { container, rerender } = render(<Header />);
fireEvent.scroll(window, { screenY: 50 });
rerender(<Header />);
fireEvent.resize(container, { innerWidth: 100, innerHeight: 100 });
rerender(<Header />);
});
});

0 comments on commit 8d41f61

Please sign in to comment.