Skip to content

Commit

Permalink
test(job): add case when using custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Jan 5, 2024
1 parent f1bfded commit 98fd1e6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,29 @@ describe('Job', function () {
expect(isFailed2).to.be.equal(true);
expect(job.stacktrace).not.be.equal(null);
expect(job.stacktrace.length).to.be.equal(1);
expect(job.stacktrace[0]).to.include('test_job.ts');
await worker.close();
});

describe('when using a custom error', function () {
it('marks the job as failed', async function () {
class CustomError extends Error {}
const worker = new Worker(queueName, null, { connection, prefix });
const token = 'my-token';
await Job.create(queue, 'test', { foo: 'bar' });
const job = (await worker.getNextJob(token)) as Job;
const isFailed = await job.isFailed();
expect(isFailed).to.be.equal(false);
await job.moveToFailed(new CustomError('test error'), '0', true);
const isFailed2 = await job.isFailed();
expect(isFailed2).to.be.equal(true);
expect(job.stacktrace).not.be.equal(null);
expect(job.stacktrace.length).to.be.equal(1);
expect(job.stacktrace[0]).to.include('test_job.ts');
await worker.close();
});
});

it('moves the job to wait for retry if attempts are given', async function () {
const queueEvents = new QueueEvents(queueName, { connection, prefix });
await queueEvents.waitUntilReady();
Expand Down

0 comments on commit 98fd1e6

Please sign in to comment.