开发者问题收集
我从未直接调用 WebSocket;它是 Asteroid 的依赖项。为什么 Jest 无法加载它?此外,这应该是默认的create-react-app测试,用于检查应用程序“渲染时不会崩溃”。但是即使 Jest 测试表明应用程序应该崩溃,它仍可以正常加载。我的提交:https://github.com/Falieson/typescript-react-asteroid-meteor/commi
我在使用以下测试用例时收到错误: Cannot read property 'weatherIconCode' of undefined我正在将weatherIconCode传递给测试用例中的组件,但我不明白为什么会出现未定义的情况。非常欢迎任何有关如何解决问题的想法并附上简要说明。组件:import React, {Component} from 'react'import IconWeathe
我正尝试使用 jest 开始进行一些单元测试,但我遇到了这个错误,似乎很多人都遇到了,但我似乎无法弄清楚。这是我正在尝试做的事情(我意识到 requirejs 不受支持):jest.mock("../widgets/", () => {return <button>button</button>;});describe('TextInput', () => {describe('when user
我有一个如下所示的函数,当我要测试该函数时,出现了上述错误。函数toggleRecovery = e => {e.preventDefault()this.setState({recovery: !this.state.recovery},() => {this.props.reset()})}测试test('if the recovery state is true should set the
Test suite failed to runJest encountered an unexpected tokenThis usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.By default, if Jest sees a B
我在 React 的一个组件内配置了一个服务,但在使用 jest 和 testing-library 时遇到了问题,应用程序可以运行,但测试被阻止了。 import { appSetupConfig } from '.../myapp'import theConfig from '.../config'useEffect(() => {const allowAppInstance = appSe
我无法从 fetch 函数访问数据。我想将数据从操作传递到 Reducer。使用 fetch 函数调用 API,api 以承诺的形式返回。因此,API 被单独调用,数据返回给操作负载。import { INDEX_PRESCRIPTION } from '../constant.js';function fetch_prescription(){const base_url= "http://19
我有 JSON 格式的产品,它们被提取并显示在前端。在我的 products.json 中,每个产品都有一个图片 URL,但只有一些产品有图片 URL,其他产品为空。当我在 React 中循环数据时,我的 React 应用程序中总是出现错误,提示无法读取<img/>标签中的 null 属性,我该如何编写一个逻辑,仅在有图片源时才渲染图片,否则只返回一个空的 div?<ul>{this.state.
我尝试使用 react useEffect hook 从https://randomuser.me/api/获取数据。我没有得到要显示的数据,而是收到一条错误,“错误:对象作为 React 子对象无效(找到:带有键 {number, name} 的对象)。如果您想要渲染子对象集合,请改用数组”。我在控制台上记录了结果,我意识到问题出在一些嵌套对象上,它们输出 [object Object]。但是,
在 onClick 事件中传递国家全名。这里是错误import React,{useState,useEffect} from 'react'; //import axios from 'axios';export const Country = (name) => {const [country, setCountry] = useState([]);const requestCountry =
无法修复此错误。我通过 fetch 方法从 thingspeak.com 接收数据(对象)。然后我想从该对象呈现三个值:名称、温度和时间。我可以看到温度和名称,但看不到时间。这是我在控制台中的错误:未捕获(在承诺中)TypeError:无法读取未定义的属性(读取“0”)。有什么想法吗?import React, { useState, useEffect } from 'react'const A
当我向 API 发出请求时,我的页面中断了,我收到了内容并将其打印在控制台上。function getFilms() {fetch('https://ghibliapi.herokuapp.com/films').then((response) => response.json()).then((data) => {console.log(data);return data;});}export
好了!我从 themeforest 购买了一些模板,预览版一切正常,但使用新版时,我遇到了类似> TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type> string. Received type undefined> at validateString (internal/validators.
我有两个页面,一个用于搜索,一个用于结果。在搜索页面中,您提交一个包含搜索项的表单,然后将其传递到 url 中。在结果页面中,我尝试读取该参数并将其作为变量传递给我在那里的函数,但是我一直收到以下错误:TypeError:无法读取未定义的属性“props”这是我的搜索页面:class Search extends Component {constructor(props){super(props)
我想在更改网址时转到下一页这是我在 React js 中为 Web 应用编写的一些代码。我正在尝试分页,但无法访问参数。我该如何访问这些参数,因为当我尝试使用console.log()时,这些参数也没有显示在控制台上。const Products = (props) => {console.log(props);const [products, setProducts] = React.useSt