1 const { expect
} = require('expect')
2 const { ThreadWorker
} = require('../../lib')
4 describe('Thread worker test suite', () => {
5 let numberOfMessagesPosted
= 0
6 const postMessage
= () => {
7 ++numberOfMessagesPosted
9 class SpyWorker
extends ThreadWorker
{
12 this.port
= { postMessage
}
16 it('Verify worker has default maxInactiveTime', () => {
17 const worker
= new ThreadWorker(() => {})
18 expect(worker
.opts
.maxInactiveTime
).toStrictEqual(60000)
21 it('Verify that handleError() method is working properly', () => {
22 const error
= new Error('Error as an error')
23 const worker
= new ThreadWorker(() => {})
24 expect(worker
.handleError(error
)).toStrictEqual(error
)
25 const errorMessage
= 'Error as a string'
26 expect(worker
.handleError(errorMessage
)).toStrictEqual(errorMessage
)
29 it('Verify worker invokes the postMessage() method on port property', () => {
30 const worker
= new SpyWorker(() => {})
31 worker
.sendToMainWorker({ ok
: 1 })
32 expect(numberOfMessagesPosted
).toBe(1)