I'm creating a web worker like this:
const getWebWorker = () => {
let worker;
if (typeof worker === 'undefined') {
worker = new Worker('worker.js');
}
return worker;
};
Then I am calling the function like this:
useEffect(() => {
getWebWorker().onmessage = (event) => {
setWorkerData(event.data);
};
}, []);
The actually worker.js file is under the public folder and postMessage's an object.
I'm using the react testing library/jest to test. When I run yarn run test I get the error ReferenceError: Worker is not defined at worker = new Worker('worker.js');.
I understand that I need to mock the worker, I'm just confused on how to.
What do I name the mock file in the __mock__ folder?
What would mocking the worker even look like?
Is there anything I have to do in the ____.test.js file?
Thanks