我对笑话和酶很陌生。在我的项目中,我将使用基于 SPA React 的应用程序。包含数据的上下文提供程序,还有几个钩子。我现在使用 Jest(带有 ts-jest 和酶)
\n我的 jest.config 看起来像这样
\nmodule.exports = {\n "roots": [\n "<rootDir>/src"\n ],\n "transform": {\n "^.+\\\\.tsx?$": "ts-jest"\n },\n "testRegex": "(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.tsx?$",\n "moduleFileExtensions": [\n "ts",\n "tsx",\n "js",\n "jsx",\n "json",\n "node"\n ],\n "snapshotSerializers": ["enzyme-to-json/serializer"]\nRun Code Online (Sandbox Code Playgroud)\n所以我的第一步是测试 UI 组件是否有效。\n下一步是使用模拟数据测试组件。但我得到了底部描述的错误。
\n我有一个像这样的功能组件:
\nexport default function CurrentWeather(props: ICurrentWeatherProps) {\n const [data, Reload] = useCurrentWeather(props.locationID);\n return (<div>......</div>)\n}\n\nRun Code Online (Sandbox Code Playgroud)\n您会注意到这个useCurrentWeather钩子,这是其代码:
import { useEffect, useState } from 'react';\nimport { useLocationState } from '../context/locationContext';\nimport { ILocationData } from './useLocations';\nimport _ …Run Code Online (Sandbox Code Playgroud)