我尝试使用spyOn 来监视函数及其实现。但是,我收到了这个错误。“无法监视原始值;给定未定义”。
我已经在https://jestjs.io/docs/en/jest-object中阅读了 jest.spyOn 的文档。但它一直显示相同的错误......有什么我应该添加和改进的吗?
下面是代码
<template>
<div>
<form @submit.prevent="onSubmit(inputValue)">
<input type="text" v-model="inputValue">
<span class="reversed">{{ reversedInput }}</span>
</form>
</div>
</template>
<script>
import axios from 'axios';
export default {
props: ['reversed'],
data: () => ({
inputValue: '',
results: [],
}),
methods: {
onSubmit(value) {
const getPromise = axios.get(
'https://jsonplaceholder.typicode.com/posts?q=' + value,
);
getPromise.then(results => {
this.results = results.data;
});
return getPromise;
},
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
而测试代码是
import axios from 'axios'; // axios here is the mock from above!
import { …Run Code Online (Sandbox Code Playgroud)