+ const worker = new ClusterWorker({ fn1, fn2 })
+ worker.getMainWorker = stub().returns({
+ id: 1,
+ send: stub().returns(),
+ })
+ expect(worker.removeTaskFunction(0, fn1)).toStrictEqual({
+ status: false,
+ error: new TypeError('name parameter is not a string'),
+ })
+ expect(worker.removeTaskFunction('', fn1)).toStrictEqual({
+ status: false,
+ error: new TypeError('name parameter is an empty string'),
+ })
+ expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+ taskFunction: expect.any(Function),
+ })
+ expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+ taskFunction: expect.any(Function),
+ })
+ expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+ taskFunction: expect.any(Function),
+ })
+ expect(worker.taskFunctions.size).toBe(3)
+ expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
+ worker.taskFunctions.get('fn1')
+ )
+ expect(worker.removeTaskFunction(DEFAULT_TASK_NAME)).toStrictEqual({
+ status: false,
+ error: new Error(
+ 'Cannot remove the task function with the default reserved name'
+ ),
+ })
+ expect(worker.removeTaskFunction('fn1')).toStrictEqual({
+ status: false,
+ error: new Error(
+ 'Cannot remove the task function used as the default task function'
+ ),
+ })
+ worker.removeTaskFunction('fn2')
+ expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+ taskFunction: expect.any(Function),
+ })
+ expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+ taskFunction: expect.any(Function),
+ })
+ expect(worker.taskFunctions.get('fn2')).toBeUndefined()
+ expect(worker.taskFunctions.size).toBe(2)
+ expect(worker.getMainWorker.calledTwice).toBe(true)
+ expect(worker.getMainWorker().send.calledOnce).toBe(true)
+ })