31 lines
784 B
JavaScript
31 lines
784 B
JavaScript
import dispatch, { init, worker } from './dispatcher-main';
|
|
|
|
var mockPostMessage = jest.fn();
|
|
|
|
jest.mock('./get-worker', () => ({
|
|
getWorker: () => ({
|
|
port: {
|
|
postMessage: jest.fn(),
|
|
},
|
|
}),
|
|
}));
|
|
|
|
describe('The dispatcher-main', () => {
|
|
beforeEach(() => {
|
|
init();
|
|
});
|
|
test('should create a new shared web worker', () => {
|
|
expect(worker).toBeDefined();
|
|
});
|
|
test('should create a onmessage function', () => {
|
|
expect(worker.port.onmessage).toBeDefined();
|
|
});
|
|
test('should return a promise if no callback is provided', () => {
|
|
expect(dispatch('ping')).toBeInstanceOf(Promise);
|
|
});
|
|
test('should send back the message', () => {
|
|
dispatch('ping');
|
|
expect(worker.port.postMessage).toBeCalledWith({ id: 0, payload: 'ping' });
|
|
});
|
|
});
|