Skip to content

Commit

Permalink
chore(utils): remove useMergeRef and add tests for useWindowSize
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrantz committed Oct 4, 2022
1 parent dc48592 commit 59350b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 51 deletions.
39 changes: 39 additions & 0 deletions packages/paste-utils/__tests__/useWindowSize.test.tsx
@@ -0,0 +1,39 @@
import * as React from 'React';
import {renderHook, act} from '@testing-library/react-hooks';
// import {render, screen} from '@testing-library/react';
import {useWindowSize} from '../src/hooks/useWindowSize';
import {Theme} from '@twilio-paste/theme';

const resizeTo = (w: number, h: number): void => {
Object.defineProperty(document.documentElement, 'clientWidth', {
value: w,
configurable: true,
});
Object.defineProperty(document.documentElement, 'clientHeight', {
value: h,
configurable: true,
});
// (window.innerWidth as number) = w;
// (window.innerHeight as number) = h;
const resizeEvent = new Event('resize', {composed: true});
window.dispatchEvent(resizeEvent);
};

const wrapper = ({children}): React.ReactElement => <Theme.Provider theme="default">{children}</Theme.Provider>;

const renderWindowSize = (): any => renderHook(() => useWindowSize(), {wrapper});

describe('useWindowSize', () => {
// jest.useFakeTimers();
beforeEach(() => {
resizeTo(150, 150);
// jest.advanceTimersByTime(100);
});

it('should get the correct width and height', () => {
const data = renderWindowSize();
console.log(data.result.current);
expect(data.result.current.width).toEqual(0);
expect(data.result.current.height).toEqual(0);
});
});
51 changes: 0 additions & 51 deletions packages/paste-utils/src/hooks/useMergeRefs.ts

This file was deleted.

0 comments on commit 59350b9

Please sign in to comment.