Skip to content

Instantly share code, notes, and snippets.

@jaysoo
Created October 15, 2019 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysoo/e5902e8b59ee8b2850ddf8514ea7307f to your computer and use it in GitHub Desktop.
Save jaysoo/e5902e8b59ee8b2850ddf8514ea7307f to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from '@testing-library/react';
import { useViewportSize } from './use-viewport-size';
describe(' UseViewportSize', () => {
it('should render successfully', () => {
// Setup
let container = document.createElement('div');
document.body.appendChild(container);
const App = () => {
const size = useViewportSize();
return <div>{JSON.stringify(size)}</div>;
};
act(() => {
ReactDOM.render(<App />, container);
});
expect(container.textContent).toEqual('{"width":1024,"height":768}');
// Teardown
document.body.removeChild(container);
container = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment