1 const expect
= require('expect')
2 const { ThreadWorker
} = require('../../lib')
4 let numberOfMessagesPosted
= 0
5 const postMessage = function (message
) {
6 numberOfMessagesPosted
++
9 class SpyWorker
extends ThreadWorker
{
11 return { postMessage
: postMessage
}
15 describe('Thread worker test suite', () => {
16 it('Verify worker has default maxInactiveTime', () => {
17 const worker
= new ThreadWorker(() => {})
18 expect(worker
.maxInactiveTime
).toEqual(60_000
)
21 it('Verify worker invoke the getMainWorker and postMessage methods', () => {
22 const worker
= new SpyWorker(() => {})
23 worker
.sendToMainWorker({ ok
: 1 })
24 expect(numberOfMessagesPosted
).toBe(1)