import { faker } from '@faker-js/faker'; import { JobError } from './JobError'; describe('JobError', () => { const requestId = faker.string.uuid(); const functionName = faker.lorem.word(); const jobName = faker.lorem.words(); const jobVersion = faker.system.semver(); it('Inherits the message and stack of the provided Error instance', () => { const error = new Error('Job code failed'); const jobError = new JobError(requestId, error, functionName, jobName, jobVersion); expect(jobError.message).toBe(error.message); expect(jobError.stack).toBe(error.stack); }); it('Inherits the message of the provided string', () => { const error = 'Job code failed'; const jobError = new JobError(requestId, error, functionName, jobName, jobVersion); expect(jobError.message).toBe(error); }); it.each([undefined, null, '', false, true])('Uses a generic message when the error is %s', (error: unknown) => { const jobError = new JobError(requestId, error, functionName, jobName, jobVersion); expect(jobError.message).toBe('An error occurred with no additional information available'); }); });