X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fworker%2Fabstract-worker.test.mjs;h=79f85cdb2030b6872c14ab74ae048d4b994707cd;hb=937d524da3a5cce4795b85ddd1c430f0d184f731;hp=b2aa996dfaa8764f6fd27c693d708807e9d790fc;hpb=2717674c56c2caae531507e7d4e0068f4d4c8918;p=poolifier.git diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index b2aa996d..79f85cdb 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -136,7 +136,7 @@ describe('Abstract worker test suite', () => { }) it('Verify that taskFunctions parameter with unique function is taken', () => { - const worker = new ThreadWorker(EMPTY_FUNCTION) + const worker = new ThreadWorker(() => {}) expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({ taskFunction: expect.any(Function) }) @@ -177,7 +177,7 @@ describe('Abstract worker test suite', () => { ).toThrow(new TypeError("Invalid property 'priority': ''")) expect( () => new ThreadWorker({ fn1: { taskFunction: fn1, priority: -21 } }) - ).toThrow(new TypeError("Property 'priority' must be between -20 and 19")) + ).toThrow(new RangeError("Property 'priority' must be between -20 and 19")) expect( () => new ThreadWorker({ fn1: { taskFunction: fn1, priority: 20 } }) ).toThrow(new RangeError("Property 'priority' must be between -20 and 19")) @@ -186,9 +186,7 @@ describe('Abstract worker test suite', () => { new ThreadWorker({ fn1: { taskFunction: fn1, strategy: 'invalidStrategy' } }) - ).toThrow( - new RangeError("Invalid worker choice strategy 'invalidStrategy'") - ) + ).toThrow(new Error("Invalid worker choice strategy 'invalidStrategy'")) }) it('Verify that taskFunctions parameter with multiple task functions is taken', () => { @@ -300,12 +298,51 @@ describe('Abstract worker test suite', () => { status: false, error: new TypeError('name parameter is an empty string') }) + expect(worker.addTaskFunction('fn2', 0)).toStrictEqual({ + status: false, + error: new TypeError( + "taskFunction object 'taskFunction' property 'undefined' is not a function" + ) + }) expect(worker.addTaskFunction('fn3', '')).toStrictEqual({ status: false, error: new TypeError( "taskFunction object 'taskFunction' property 'undefined' is not a function" ) }) + expect(worker.addTaskFunction('fn2', { taskFunction: 0 })).toStrictEqual({ + status: false, + error: new TypeError( + "taskFunction object 'taskFunction' property '0' is not a function" + ) + }) + expect(worker.addTaskFunction('fn3', { taskFunction: '' })).toStrictEqual({ + status: false, + error: new TypeError( + "taskFunction object 'taskFunction' property '' is not a function" + ) + }) + expect( + worker.addTaskFunction('fn2', { taskFunction: () => {}, priority: -21 }) + ).toStrictEqual({ + status: false, + error: new RangeError("Property 'priority' must be between -20 and 19") + }) + expect( + worker.addTaskFunction('fn3', { taskFunction: () => {}, priority: 20 }) + ).toStrictEqual({ + status: false, + error: new RangeError("Property 'priority' must be between -20 and 19") + }) + expect( + worker.addTaskFunction('fn2', { + taskFunction: () => {}, + strategy: 'invalidStrategy' + }) + ).toStrictEqual({ + status: false, + error: new Error("Invalid worker choice strategy 'invalidStrategy'") + }) expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({ taskFunction: expect.any(Function) })