Commit | Line | Data |
---|---|---|
fd027a65 S |
1 | const expect = require('expect') |
2 | const { ThreadWorker } = require('../../lib') | |
3 | ||
74a2a194 | 4 | let numberOfMessagesPosted = 0 |
8d3782fa | 5 | const postMessage = function () { |
74a2a194 | 6 | numberOfMessagesPosted++ |
74a2a194 APA |
7 | } |
8 | class SpyWorker extends ThreadWorker { | |
9 | getMainWorker () { | |
10 | return { postMessage: postMessage } | |
11 | } | |
12 | } | |
13 | ||
fd027a65 S |
14 | describe('Thread worker test suite', () => { |
15 | it('Verify worker has default maxInactiveTime', () => { | |
16 | const worker = new ThreadWorker(() => {}) | |
17 | expect(worker.maxInactiveTime).toEqual(60_000) | |
18 | }) | |
74a2a194 APA |
19 | |
20 | it('Verify worker invoke the getMainWorker and postMessage methods', () => { | |
21 | const worker = new SpyWorker(() => {}) | |
22 | worker.sendToMainWorker({ ok: 1 }) | |
23 | expect(numberOfMessagesPosted).toBe(1) | |
24 | }) | |
fd027a65 | 25 | }) |