Mock web worker.

This commit is contained in:
Kia Lam 2022-03-08 10:13:47 -08:00
parent 4040e09cb8
commit 079eed2b9e
5 changed files with 8 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import { mountWithContexts } from '../testUtils/enzymeHelpers';
import App, { ProtectedRoute } from './App';
jest.mock('./api');
jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn());
describe('<App />', () => {
beforeEach(() => {

View File

@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import App from './App';
jest.mock('react-dom', () => ({ render: jest.fn() }));
jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn());
describe('index.jsx', () => {
it('renders ok', () => {

View File

@ -1,4 +1,5 @@
import getRouteConfig from './routeConfig';
jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn());
const userProfile = {
isSuperUser: false,

View File

@ -17,6 +17,7 @@ import {
// generateRandomNodes,
// getRandomInt,
} from './utils/helpers';
import webWorker from './utils/webWorker';
import {
DEFAULT_RADIUS,
DEFAULT_NODE_COLOR,
@ -59,10 +60,7 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
const graph = data;
/* WEB WORKER */
const worker = new Worker(
new URL('./utils/workers/simulationWorker.js', import.meta.url)
);
const worker = webWorker();
worker.postMessage({
nodes: graph.nodes,
links: graph.links,

View File

@ -0,0 +1,3 @@
export default function webWorker() {
return new Worker(new URL('./workers/simulationWorker.js', import.meta.url));
}