问题描述
export default class Test extends Vue {
mounted() {
this.getData();
eventBus.$on("get",(id: string) => {
this.displayData(id);
});
}
getData(){
return "hello"
}
displayData(id){
}
我已经为Test组件编写了规格,如下所示。我已经使用了全局事件总线,并尝试检查事件是否发出。
const EventBus = new Vue();
const GlobalPlugins = {
install(v:any) {
// Event bus
v.prototype.eventBus = EventBus;
}
};
const localVue = createLocalVue()
localVue.prototype.eventBus = createLocalVue();
localVue.use(GlobalPlugins);
describe('Test TestSuite',() => {
let wrapper: any
let TestObj: any;
beforeEach(() => {
const mocks = {
eventBus: {
$on: jest.fn(),$emit: jest.fn()
}
};
wrapper = mount(Test,{
mocks,localVue,router
});
console.log(eventBus.$emit) ---> returns null
TestObj = wrapper.findComponent(Test).vm;
console.log(eventBus.$emit) ---> returns null
});
在这里,我尝试检查get事件是否发出。但它只提供空对象。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)