Skip to content

Commit

Permalink
Fix test in log table report and useasync function
Browse files Browse the repository at this point in the history
Signed-off-by: angatupyry <fierrofenix@gmail.com>
  • Loading branch information
Angatupyry committed Jul 13, 2023
1 parent b776e54 commit 0615881
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanup, render, RenderResult, screen, fireEvent } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import { format } from 'date-fns';
import React from 'react';
import { LogLevel } from './log-level';
Expand All @@ -25,16 +25,11 @@ for (let i = 0; i < 110; i++) {
}

describe('Log table test', () => {
// beforeEach(() => {
// render(<LogTable rows={rows} />);
// });

afterEach(cleanup);

// it('formats dates correctly', async () => {
// const tableFirstDateElement = (await root.getAllByTestId('log-table-date'))[0];
// expect(tableFirstDateElement.innerHTML).toBe(format(timestamp, 'MMM dd yyyy hh:mm aaa'));
// });
it('formats dates correctly', async () => {
const { getAllByTestId } = render(<LogTable rows={rows} />);
const tableFirstDateElement = (await getAllByTestId('log-table-date'))[0];
expect(tableFirstDateElement.innerHTML).toBe(format(timestamp, 'MMM dd yyyy hh:mm aaa'));
});

it('shows the correct number of rows', () => {
const { container } = render(<LogTable rows={rows} />);
Expand All @@ -44,12 +39,6 @@ describe('Log table test', () => {
});

describe('Table footer Pagination', () => {
// beforeEach(() => {
// render(<LogTable rows={rows} />);
// });

// afterEach(cleanup);

it('show the correct number of rows per page', () => {
render(<LogTable rows={rows} />);
// NOTE: mui v5 is using the unicode char '–', different from '-'!!
Expand Down
17 changes: 8 additions & 9 deletions packages/react-components/lib/use-async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ describe('useAsync', () => {
await expectAsync(safeAsync(Promise.reject('test error'))).toBeRejectedWith('test error');
});

// Commented due to the change to react 18 and because the hooks are not currently being used.
// TODO[CR]: Eliminate before PR

// it('referentially equal across renders', () => {
// const hook = renderHook(() => useAsync(true));
// hook.rerender();
// expect(hook.result.all.length).toBe(2);
// expect(hook.result.all[0]).toBe(hook.result.all[1]);
// });
it('referentially equal across renders', async () => {
const hook = renderHook(() => useAsync(true));
const { rerender } = renderHook((props) => useAsync(props.throwOnUnmounted), {
initialProps: { throwOnUnmounted: true },
});
expect(rerender).toBeDefined();
expect(hook.result.current[0]).toBe(hook.result.current[1]);
});
});

0 comments on commit 0615881

Please sign in to comment.