docs: refine comment decorator
[poolifier.git] / tests / worker / cluster-worker.test.mjs
CommitLineData
a074ffee
JB
1import { expect } from 'expect'
2import { ClusterWorker } from '../../lib/index.js'
fd027a65
S
3
4describe('Cluster worker test suite', () => {
f4fb3543 5 let numberOfMessagesSent = 0
440dd7d7 6 const send = () => {
f4fb3543
JB
7 ++numberOfMessagesSent
8 }
9 class SpyWorker extends ClusterWorker {
10 getMainWorker () {
11 return { send }
12 }
13 }
14
18ecc6c5
JB
15 it('Verify that handleError() method is working properly', () => {
16 const error = new Error('Error as an error')
17 const worker = new ClusterWorker(() => {})
18 expect(worker.handleError(error)).not.toBeInstanceOf(Error)
19 expect(worker.handleError(error)).toStrictEqual(error.message)
20 const errorMessage = 'Error as a string'
21 expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage)
22 })
23
2431bdb4 24 it('Verify worker invokes the getMainWorker() and send() methods', () => {
f4fb3543
JB
25 const worker = new SpyWorker(() => {})
26 worker.sendToMainWorker({ ok: 1 })
27 expect(numberOfMessagesSent).toBe(1)
28 })
fd027a65 29})