我目前有以下 Vue 页面代码:
<template>
// Button that when clicked called submit method
</template>
<script>
import { moveTo } from '@/lib/utils';
export default {
components: {
},
data() {
},
methods: {
async submit() {
moveTo(this, COMPLETE_ACTION.path, null);
},
},
};
</script>
然后我有这个页面的测试文件。我的问题是我试图检查并断言 moveTo 方法是使用 Jest 使用正确的参数调用的。它一直显示预期的未定义但收到了一个对象。以下是测试文件中的关键点:
import * as dependency from '@/lib/utils';
dependency.moveTo = jest.fn();
// I then trigger the button call which calls the submit method on the page
expect(dependency.moveTo).toHaveBeenCalledWith(this, COMPLETE_ACTION.path, null);
我不确定在这种情况下这是什么以及我实际上应该传递什么。请注意我正在使用来自 vue 测试工具的挂载助手。