Scenes: Unset _changesWorker when change tracker is terminated (#89495)

* Scenes: Unset _changesWorker when change tracker is terminated

Closes #89458
This commit is contained in:
kay delaney
2024-06-21 13:18:52 +03:00
committed by GitHub
parent e5474511d8
commit d750af0c48
3 changed files with 28 additions and 0 deletions
+4
View File
@@ -2838,6 +2838,10 @@ exports[`better eslint`] = {
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "2"], [0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "2"],
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "3"] [0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "3"]
], ],
"public/app/features/dashboard-scene/saving/DashboardSceneChangeTracker.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx:5381": [ "public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx:5381": [
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"], [0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"], [0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
@@ -0,0 +1,23 @@
import * as createDetectChangesWorker from 'app/features/dashboard-scene/saving/createDetectChangesWorker';
import { DashboardSceneChangeTracker } from './DashboardSceneChangeTracker';
describe('DashboardSceneChangeTracker', () => {
it('should set _changesWorker to undefined when terminate is called', () => {
const terminate = jest.fn();
jest.spyOn(createDetectChangesWorker, 'createWorker').mockImplementation(
() =>
({
terminate,
}) as any
);
const changeTracker = new DashboardSceneChangeTracker({
subscribeToEvent: jest.fn().mockReturnValue({ unsubscribe: jest.fn() }),
} as any);
changeTracker.startTrackingChanges();
expect(changeTracker['_changesWorker']).not.toBeUndefined();
changeTracker.terminate();
expect(changeTracker['_changesWorker']).toBeUndefined();
});
});
@@ -188,5 +188,6 @@ export class DashboardSceneChangeTracker {
public terminate() { public terminate() {
this.stopTrackingChanges(); this.stopTrackingChanges();
this._changesWorker?.terminate(); this._changesWorker?.terminate();
this._changesWorker = undefined;
} }
} }