@axinom/mosaic-ui
Version:
UI components for building Axinom Mosaic applications
33 lines (28 loc) • 1.13 kB
text/typescript
import { ErrorType } from '../../../components';
import { ApolloErrorMapper } from './ApolloErrorMapper';
describe('ApolloErrorMapper', () => {
const mockError: ErrorType = {
name: 'ApolloError',
networkError: { message: 'Network connection lost' },
};
it('should map an Apollo error with a network error', () => {
const mappedError = ApolloErrorMapper(mockError);
expect(mappedError).toEqual({
title: 'A network error occurred',
body: expect.any(Object), // You can modify the expectation here based on your needs
});
});
it('should not map an error if already mapped by a previous error mapper', () => {
const previousMappedError: ErrorType = {
title: 'Previous Error',
body: 'Previous error message',
};
const mappedError = ApolloErrorMapper(mockError, previousMappedError);
expect(mappedError).toBeUndefined();
});
it('should return undefined if it does not match the conditions', () => {
const error: ErrorType = new Error('Some other error');
const mappedError = ApolloErrorMapper(error);
expect(mappedError).toBeUndefined();
});
});