Commit f8dc00b4 authored by Enrique Alcantara's avatar Enrique Alcantara

Code review feedbac

Disconnect mutationobserver when component is destroyed
parent e0b027b6
......@@ -43,6 +43,9 @@ export default {
});
});
},
beforeDestroy() {
this.observer.disconnect();
},
methods: {
addTooltips(elements, config) {
const newTooltips = elements
......
......@@ -84,7 +84,9 @@ const useMockObserver = (key, createMock) => {
mockObserver.$_triggerObserve(...args);
};
return { trigger };
const observersCount = () => mockObserver.$_observers.length;
return { trigger, observersCount };
};
export const useMockIntersectionObserver = () =>
......
import { shallowMount } from '@vue/test-utils';
import { GlTooltip } from '@gitlab/ui';
import Tooltips from '~/tooltips/components/tooltips.vue';
import { useMockMutationObserver } from 'helpers/mock_dom_observer';
import Tooltips from '~/tooltips/components/tooltips.vue';
describe('tooltips/components/tooltips.vue', () => {
const { trigger: triggerMutate } = useMockMutationObserver();
const { trigger: triggerMutate, observersCount } = useMockMutationObserver();
let wrapper;
const buildWrapper = () => {
......@@ -147,4 +147,14 @@ describe('tooltips/components/tooltips.vue', () => {
expect(allTooltips()).toHaveLength(1);
});
});
it('disconnects mutation observer on beforeDestroy', () => {
buildWrapper();
wrapper.vm.addTooltips([createTooltipTarget()]);
expect(observersCount()).toBe(1);
wrapper.destroy();
expect(observersCount()).toBe(0);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment