diff --git a/app/assets/javascripts/vue_shared/plugins/global_toast.js b/app/assets/javascripts/vue_shared/plugins/global_toast.js index fb52b31c2c8fea4ed9e96eda60e8b3a81d832114..bfea2bedd403c10164be52ce5dc9e52ad3da1b66 100644 --- a/app/assets/javascripts/vue_shared/plugins/global_toast.js +++ b/app/assets/javascripts/vue_shared/plugins/global_toast.js @@ -2,7 +2,7 @@ import { GlToast } from '@gitlab/ui'; import Vue from 'vue'; Vue.use(GlToast); -export const instance = new Vue(); +const instance = new Vue(); export default function showGlobalToast(...args) { return instance.$toast.show(...args); diff --git a/spec/frontend/vue_shared/plugins/global_toast_spec.js b/spec/frontend/vue_shared/plugins/global_toast_spec.js index 322586a772c9b258a2a19684d3d7bdc59e80bc3f..0bf2737fb2bf97435dc76bb255b507f24e1bdb8e 100644 --- a/spec/frontend/vue_shared/plugins/global_toast_spec.js +++ b/spec/frontend/vue_shared/plugins/global_toast_spec.js @@ -1,14 +1,16 @@ -import toast, { instance } from '~/vue_shared/plugins/global_toast'; +import toast from '~/vue_shared/plugins/global_toast'; -describe('Global toast', () => { - let spyFunc; - - beforeEach(() => { - spyFunc = jest.spyOn(instance.$toast, 'show').mockImplementation(() => {}); - }); +const mockSpy = jest.fn(); +jest.mock('@gitlab/ui', () => ({ + GlToast: (Vue) => { + // eslint-disable-next-line no-param-reassign + Vue.prototype.$toast = { show: (...args) => mockSpy(...args) }; + }, +})); +describe('Global toast', () => { afterEach(() => { - spyFunc.mockRestore(); + mockSpy.mockRestore(); }); it("should call GitLab UI's toast method", () => { @@ -17,7 +19,7 @@ describe('Global toast', () => { toast(arg1, arg2); - expect(instance.$toast.show).toHaveBeenCalledTimes(1); - expect(instance.$toast.show).toHaveBeenCalledWith(arg1, arg2); + expect(mockSpy).toHaveBeenCalledTimes(1); + expect(mockSpy).toHaveBeenCalledWith(arg1, arg2); }); });