【发布时间】:2019-08-10 10:49:10
【问题描述】:
我目前有以下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);
我不确定在这种情况下 this 是什么以及我应该实际传递什么。请注意我正在使用 vue 测试工具中的挂载助手。
【问题讨论】:
标签: javascript vue.js jestjs