Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
salazarm committed Dec 10, 2024
1 parent 7b6fe56 commit fecad18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import {ComputeGraphDataMessageType} from '../../src/asset-graph/ComputeGraphDat

// eslint-disable-next-line import/no-default-export
export default class MockWorker {
onmessage = (_: any) => {};
onmessage: Array<(data: any) => void> = [];

addEventListener(_type: string, handler: any) {
this.onmessage = handler;
this.onmessage.push(handler);
}

removeEventListener(_type: string, handler: any) {
const index = this.onmessage.indexOf(handler);
if (index !== -1) {
this.onmessage.splice(index, 1);
}
}

// mock expects data: { } instead of e: { data: { } }
Expand All @@ -17,7 +24,7 @@ export default class MockWorker {
setFeatureFlagsInternal({flagAssetSelectionSyntax: true});
}
const state = await computeGraphData(data);
this.onmessage({data: {...state, id: data.id}});
this.onmessage.forEach((onmessage) => onmessage({data: {...state, id: data.id}}));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ import '../../../jest/mocks/ComputeGraphData.worker';

// This file must be mocked because Jest can't handle `import.meta.url`.
jest.mock('../../graph/asyncGraphLayout', () => ({}));
jest.mock(
'lodash/throttle',
() =>
(fn: (...args: any[]) => any) =>
jest.mock('../../asset-graph/throttleLatest', () => ({
throttleLatest:
(fn: any) =>
(...args: any[]) =>
fn(...args),
);
}));

// These files must be mocked because useVirtualizer tries to create a ResizeObserver,
// and the component tree fails to mount.
Expand Down

0 comments on commit fecad18

Please sign in to comment.