Commit 062547ce authored by Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt Committed by Kushal Pandya

Use GitLab UI toast in global_toast

parent 9514d151
...@@ -2,7 +2,8 @@ import Vue from 'vue'; ...@@ -2,7 +2,8 @@ import Vue from 'vue';
import { GlToast } from '@gitlab/ui'; import { GlToast } from '@gitlab/ui';
Vue.use(GlToast); Vue.use(GlToast);
const instance = new Vue();
export default function showGlobalToast(...args) { export default function showGlobalToast(...args) {
return Vue.toasted.show(...args); return instance.$toast.show(...args);
} }
import toast from '~/vue_shared/plugins/global_toast';
import Vue from 'vue'; import Vue from 'vue';
import toast from '~/vue_shared/plugins/global_toast';
describe('Global toast', () => { describe('Global toast', () => {
let spyFunc; let spyFunc;
beforeEach(() => { beforeEach(() => {
spyFunc = jest.spyOn(Vue.toasted, 'show').mockImplementation(() => {}); spyFunc = jest.spyOn(Vue.prototype.$toast, 'show').mockImplementation(() => {});
}); });
afterEach(() => { afterEach(() => {
spyFunc.mockRestore(); spyFunc.mockRestore();
}); });
it('should pass all args to Vue toasted', () => { it("should call GitLab UI's toast method", () => {
const arg1 = 'TestMessage'; const arg1 = 'TestMessage';
const arg2 = { className: 'foo' }; const arg2 = { className: 'foo' };
toast(arg1, arg2); toast(arg1, arg2);
expect(Vue.toasted.show).toHaveBeenCalledTimes(1); expect(Vue.prototype.$toast.show).toHaveBeenCalledTimes(1);
expect(Vue.toasted.show).toHaveBeenCalledWith(arg1, arg2); expect(Vue.prototype.$toast.show).toHaveBeenCalledWith(arg1, arg2);
}); });
}); });
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