worker-mock
v0.0.3
Published
worker mock for tests
Downloads
1,271
Readme
worker-mock
Class for emitting events
Install
npm
npm install worker-mock
yarn
yarn add worker-mock
Usage
import workerMockTools from 'worker-mock';
const { createWorkerMock, resolveWorkerForClient } = workerMockTools;
const workerMock = createWorkerMock();
workerMock.addEventListener('message', (e) => {
console.log('Message received from client script: ', e);
workerMock.postMessage('Hello from worker!');
});
const workerMockForClient = resolveWorkerForClient(workerMock);
workerMockForClient.addEventListener('message', (e) => {
console.log('Message received from worker script: ', e);
});
workerMockForClient.postMessage('Hello from client!');
// Message received from client script: Hello from client!
// Message received from client script: Hello from worker!
// and some helpers
workerMock.triggerWorkerEvent('message', 'some data'); // trigger for inner message in worker
workerMock.onPostMessageFromWorker(() => {
// called after postMessage in worker
});
Maintainer
👤 Krivega Dmitriy
- Website: https://krivega.com
- Github: @Krivega
Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.
📝 License
Copyright © 2020 Krivega Dmitriy. This project is MIT licensed.