import React from 'react'; import renderer from 'react-test-renderer'; import { render, fireEvent } from '@testing-library/react'; import moment from 'moment'; import { TranslationProvider } from '../context/TranslationContext'; import { UserBar } from './UserBar'; // @ts-expect-error Date.now = jest.fn(() => new Date('2021-04-15T11:34:36.104Z')); describe('UserBar', () => { it('renders with default props', () => { const tree = renderer.create(); expect(tree).toMatchInlineSnapshot(`

batman

`); }); it('renders with custom props', () => { const tree = renderer.create( v, tDateTimeParser: moment }}> Gotham City} icon="https://pics.freeicons.io/uploads/icons/png/4781616661579237635-24.png" timestamp="2021-04-08T10:52:02.250Z" subtitle="The Dark Knight Rises" /> , ); expect(tree).toMatchInlineSnapshot(`

Batman

icon

`); }); it('renders with time property defined', () => { const tree = renderer.create(); expect(tree).toMatchInlineSnapshot(`

Batman

`); }); it('checks if onClick has been called', () => { const handleClick = jest.fn(); const { getByTestId } = render(); fireEvent.click(getByTestId('user-bar-username')); expect(handleClick).toHaveBeenCalledTimes(1); }); });