docbrown/app/javascript/shared/components/__tests__/dateTime.test.jsx
dependabot[bot] f0700b2588
Bump jest from 26.6.3 to 27.2.0 (#14722)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2021-09-14 11:20:15 -04:00

42 lines
1.2 KiB
JavaScript

import { h } from 'preact';
import { axe } from 'jest-axe';
import { render } from '@testing-library/preact';
import '@testing-library/jest-dom';
import { DateTime } from '../dateTime';
import '../../../../assets/javascripts/utilities/localDateTime';
/* eslint-disable no-unused-vars */
/* global globalThis timestampToLocalDateTimeLong timestampToLocalDateTimeShort */
describe('<DateTime />', () => {
afterAll(() => {
delete globalThis.timestampToLocalDateTimeLong;
delete globalThis.timestampToLocalDateTimeShort;
});
it('should have no a11y violations', async () => {
const { container } = render(
<DateTime
className="date-time"
dateTime={new Date('2019-09-20T17:26:20.531Z')}
/>,
);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('should render given datetime', () => {
const { getByText } = render(
<DateTime
className="date-time"
dateTime={new Date('2019-09-10T17:26:20.531Z')}
/>,
);
const dateTime = getByText('Sep 10, 2019');
expect(dateTime.title).toBe('Tuesday, September 10, 2019, 5:26:20 PM');
expect(dateTime).toHaveClass('date-time');
});
});