我正在尝试将 Jest 引入我当前的项目。
\n然而,在初始设置过程中,我遇到了这个错误,并且无法正常运行。
\n我该如何解决这个问题?
\n我目前正在使用 vue-cli 中的 vue2。
\n\xe2\x97\x8f Test suite failed to run\n\n TypeError: Cannot read properties of undefined (reading 'html')\n\n at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:72:44)\n at async TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)\n at async runJest (node_modules/@jest/core/build/runJest.js:407:19)\n at async _run10000 (node_modules/@jest/core/build/cli/index.js:338:7)\n at async runCLI (node_modules/@jest/core/build/cli/index.js:190:3)\nRun Code Online (Sandbox Code Playgroud)\n这是我的测试代码。
\nimport SettlementProcessing from "@/views/calculate/SettlementProcessing.vue";\nimport { shallowMount } from "@vue/test-utils";\nimport Vuetify from "vuetify";\ndescribe("Settlement Component", () => {\n let vuetify;\n beforeEach(() => {\n vuetify = new Vuetify();\n });\n it("\xec\xa0\x95\xec\x82\xb0 \xec\xb2\x98\xeb\xa6\xac \xed\x83\x80\xec\x9d\xb4\xed\x8b\x80\xec\x9d\xb4 \xeb\x82\x98\xec\x99\x80\xec\x95\xbc …Run Code Online (Sandbox Code Playgroud) 我正在开发一个用于每页身份验证的 useUser Hook。我已经正常实现了 useUser 挂钩,因此重定向工作正常。但我收到上述错误。
中止获取路由组件:“/login”
我该如何修复 useUserHook 来解决它?
//useUser.tsx
const useUser = ({ redirectTo, redirectIfFound }: IParams) => {
const { data, error } = useRequest("authed", isAuthed);
const user = data?.data;
const hasUser = user;
useEffect(() => {
if (!redirectTo) return;
if (
// If redirectTo is set, redirect if the user was not found.
(redirectTo && !redirectIfFound && !hasUser) ||
// If redirectIfFound is also set, redirect if the user was found
(redirectIfFound && hasUser)
) {
Router.push(redirectTo); …Run Code Online (Sandbox Code Playgroud) 我想知道如何在输入日期中设置占位符。
\n这是我的代码
\n<input type="text" onChange={(e) => { setbirth(moment(e.target.value).format('YYYYMMDD')) }} placeholder="\xec\x83\x9d\xeb\x85\x84\xec\x9b\x94\xec\x9d\xbc" onFocus="(this.type = 'date')" onBlur="(this.type='text')" />\nRun Code Online (Sandbox Code Playgroud)\n我已经查看了这个问题,但是使用此代码\n会引发错误。
\nonfocus="(this.type='date')" onblur="(this.type='text')"\n\n\nWarning: Expected `onFocus` listener to be a function, instead got a value of `string` type.\nWarning: Expected `onBlur` listener to be a function, instead got a value of `string` type.\nRun Code Online (Sandbox Code Playgroud)\n有什么办法可以改而不报错吗?
\n我们正在将 Jest 引入现有项目。
不过,我写了一个示例测试代码。出现上述错误。
ReferenceError: Vue is not defined
1 | import User from "../components/modal/ad/AdAdd";
> 2 | import { mount } from "@vue/test-utils";
| ^
3 |
4 | describe("user component", () => {
5 | let wrapper;
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
ReferenceError: Vue is not defined
1 | import User from "../components/modal/ad/AdAdd";
> 2 | import { mount } from "@vue/test-utils";
| ^
3 |
4 | describe("user component", () => {
5 | let wrapper;
Run Code Online (Sandbox Code Playgroud)
//User.test.js
import User from "../components/modal/ad/AdAdd"; …Run Code Online (Sandbox Code Playgroud) 我正在使用 React Query 制作访客呼叫系统。
我有一种调用(按钮),我只想在按下按钮时调用 api。然而,当组件被渲染时,它会不断调用 api。
我应该怎么办?
//App.jsx
const query = useQuery('resData', getEmployData('datas'), {
enabled: false
});
const callBtn = () => {
query.refetch()
}
return (
<ul>
<li onClick ={callBtn}>Post</li>
<li>Food</li>
<li>Other</li>
</ul>
)
Run Code Online (Sandbox Code Playgroud)
这是api函数
const getEmployData = async(callKind) => {
const {data} = await axios.get(`${baseUrl}/welcome?callKind=${callKind}`);
return data
}
Run Code Online (Sandbox Code Playgroud) jestjs ×2
reactjs ×2
vue-jest ×2
vuejs2 ×2
css ×1
html ×1
javascript ×1
next-router ×1
next.js ×1
react-query ×1
vue-cli ×1
vue.js ×1