refactor: cleanup .gitignore
[poolifier.git] / tests / worker / thread-worker.test.mjs
1 import { expect } from 'expect'
2 import { ThreadWorker } from '../../lib/index.js'
3
4 describe('Thread worker test suite', () => {
5 let numberOfMessagesPosted = 0
6 const postMessage = () => {
7 ++numberOfMessagesPosted
8 }
9 class SpyWorker extends ThreadWorker {
10 constructor (fn) {
11 super(fn)
12 this.port = { postMessage }
13 }
14 }
15
16 it('Verify that handleError() method is working properly', () => {
17 const error = new Error('Error as an error')
18 const worker = new ThreadWorker(() => {})
19 expect(worker.handleError(error)).toStrictEqual(error)
20 const errorMessage = 'Error as a string'
21 expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage)
22 })
23
24 it('Verify worker invokes the postMessage() method on port property', () => {
25 const worker = new SpyWorker(() => {})
26 worker.sendToMainWorker({ ok: 1 })
27 expect(numberOfMessagesPosted).toBe(1)
28 })
29 })