import Vue from "vue";
import ModalPlugin from "@/plugins/modal/ModalPlugin";
...
Vue.use(ModalPlugin);
...
new Vue({ ... })
import ModalDialog from "@/ui/modals/ModalDialog";
methods: {
...
myShowModalFn() {
this.$modal.create({
// The names of properties do matter!
id: "foo", // Required, unique, string or number
modalComponent: ModalDialog, // Required, vue-component
text: "Lorem ipsum", // Optional
props: {
myFirstPropName: myFirstPropValue,
mySecondPropName: mySecondPropValue,
....
}, // Optional
onConfirm: someFn, // Optional, async fn is ok
onCancel: someFn, // Optional, async fn is ok
});
this.$modal.show("foo"); // Pass an id of modal here
},
myHideModalFn() {
this.$modal.hide("foo"); // Pass an id of modal here
}
}
disabled: {
type: Boolean,
},
text: {
type: String,
},
isVisible: {
type: Boolean,
},
// wrapper here is the VTU-wrapper for component where the modal was created
const modalCreateSpyOn = jest.spyOn(wrapper.vm.$modal, "create");
// do something to show a modal (click on button for instance)
expect(modalCreateSpyOn).toHaveBeenCalled();
expect(modalCreateSpyOn).toHaveBeenCalledWith({
id: `your-expected-id`,
modalComponent: `YourExpectedComponent`,
text: `your-expected-text`,
onCancel: expect.any(Function), // or particular fn
onConfirm: expect.any(Function), // or particular fn
});
modalCreateSpyOn.mockReset();