Skip to content
代码片段 群组 项目
提交 f6fe9df7 编辑于 作者: Natalia Tepluhina's avatar Natalia Tepluhina
浏览文件

Merge branch 'xanf-refactor-global-toast' into 'master'

Refactor global_toast to avoid instance export

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114071



Merged-by: default avatarNatalia Tepluhina <ntepluhina@gitlab.com>
Approved-by: default avatarTomas Bulva <tbulva@gitlab.com>
Approved-by: default avatarNatalia Tepluhina <ntepluhina@gitlab.com>
Co-authored-by: default avatarIllya Klymov <xanf@xanf.me>
No related branches found
No related tags found
无相关合并请求
...@@ -2,7 +2,7 @@ import { GlToast } from '@gitlab/ui'; ...@@ -2,7 +2,7 @@ import { GlToast } from '@gitlab/ui';
import Vue from 'vue'; import Vue from 'vue';
Vue.use(GlToast); Vue.use(GlToast);
export const instance = new Vue(); const instance = new Vue();
export default function showGlobalToast(...args) { export default function showGlobalToast(...args) {
return instance.$toast.show(...args); return instance.$toast.show(...args);
......
import toast, { instance } from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
describe('Global toast', () => { const mockSpy = jest.fn();
let spyFunc; jest.mock('@gitlab/ui', () => ({
GlToast: (Vue) => {
beforeEach(() => { // eslint-disable-next-line no-param-reassign
spyFunc = jest.spyOn(instance.$toast, 'show').mockImplementation(() => {}); Vue.prototype.$toast = { show: (...args) => mockSpy(...args) };
}); },
}));
describe('Global toast', () => {
afterEach(() => { afterEach(() => {
spyFunc.mockRestore(); mockSpy.mockRestore();
}); });
it("should call GitLab UI's toast method", () => { it("should call GitLab UI's toast method", () => {
...@@ -17,7 +19,7 @@ describe('Global toast', () => { ...@@ -17,7 +19,7 @@ describe('Global toast', () => {
toast(arg1, arg2); toast(arg1, arg2);
expect(instance.$toast.show).toHaveBeenCalledTimes(1); expect(mockSpy).toHaveBeenCalledTimes(1);
expect(instance.$toast.show).toHaveBeenCalledWith(arg1, arg2); expect(mockSpy).toHaveBeenCalledWith(arg1, arg2);
}); });
}); });
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册