Skip to content

Commit

Permalink
test: add test for error boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
Prithpal-Sooriya committed Feb 24, 2025
1 parent 6fc8cda commit 12324bf
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { FC } from 'react';
import { render } from '@testing-library/react';
import log from 'loglevel';
import NFTGridItemErrorBoundary from './nft-grid-item-error-boundary';

describe('NFTGridItemErrorBoundary tests', () => {
it('should fallback if grid item crashes', () => {
const mockError = jest.spyOn(log, 'error').mockImplementation(jest.fn());

const MockGridItem: FC = () => {
throw new Error('Mock Error');
};

const { container } = render(
<NFTGridItemErrorBoundary fallback={() => null}>
<MockGridItem />
</NFTGridItemErrorBoundary>,
);

expect(container).toBeEmptyDOMElement();
expect(mockError).toHaveBeenCalled();
});
});

0 comments on commit 12324bf

Please sign in to comment.