diff --git a/src/utils/Time.tsx b/src/utils/Time.tsx
index c50639a2..fc4c3571 100644
--- a/src/utils/Time.tsx
+++ b/src/utils/Time.tsx
@@ -1,13 +1,13 @@
import { parseISO, format as formatDate, getUnixTime, formatDistance } from 'date-fns';
import { isDateObject } from './helpers/date';
-export interface DateProps {
+export interface TimeProps {
date: Date | string;
format?: string;
relative?: boolean;
}
-export const Time = ({ date, format = 'yyyy-MM-dd HH:mm', relative = false }: DateProps) => {
+export const Time = ({ date, format = 'yyyy-MM-dd HH:mm', relative = false }: TimeProps) => {
const dateObject = isDateObject(date) ? date : parseISO(date);
return (
diff --git a/test/utils/Time.test.tsx b/test/utils/Time.test.tsx
index a62dc06c..cb1f9c8f 100644
--- a/test/utils/Time.test.tsx
+++ b/test/utils/Time.test.tsx
@@ -1,30 +1,22 @@
-import { shallow, ShallowWrapper } from 'enzyme';
-import { DateProps, Time } from '../../src/utils/Time';
+import { render } from '@testing-library/react';
+import { TimeProps, Time } from '../../src/utils/Time';
import { parseDate } from '../../src/utils/helpers/date';
describe('', () => {
- let wrapper: ShallowWrapper;
- const createWrapper = (props: DateProps) => {
- wrapper = shallow();
-
- return wrapper;
- };
-
- afterEach(() => wrapper?.unmount());
+ const setUp = (props: TimeProps) => render();
it.each([
[{ date: parseDate('2020-05-05', 'yyyy-MM-dd') }, '1588636800000', '2020-05-05 00:00'],
[{ date: parseDate('2021-03-20', 'yyyy-MM-dd'), format: 'dd/MM/yyyy' }, '1616198400000', '20/03/2021'],
])('includes expected dateTime and format', (props, expectedDateTime, expectedFormatted) => {
- const wrapper = createWrapper(props);
+ const { container } = setUp(props);
- expect(wrapper.prop('dateTime')).toEqual(expectedDateTime);
- expect(wrapper.prop('children')).toEqual(expectedFormatted);
+ expect(container.firstChild).toHaveAttribute('datetime', expectedDateTime);
+ expect(container.firstChild).toHaveTextContent(expectedFormatted);
});
it('renders relative times when requested', () => {
- const wrapper = createWrapper({ date: new Date(), relative: true });
-
- expect(wrapper.prop('children')).toContain(' ago');
+ const { container } = setUp({ date: new Date(), relative: true });
+ expect(container.firstChild).toHaveTextContent(' ago');
});
});