使用jest和酶在react中编写单元测试。在检查组件状态时,它抛出错误"ReactWrapper:: state ()仅能在类组件上调用“。 import React from 'react';
import { mount } from 'enzyme';
import expect from 'expect';
import CustomerAdd from '../CustomerAdd'
import MUITheme from '../../../../Utilities/MUITheme';
我正在尝试使用jest和react测试库对自定义钩子进行单元测试,在这种情况下抛出错误,但我无法捕获实际的错误消息,以下是我到目前为止的代码:
我的第一个钩子:
import react from 'react';
const useFirstHook = () => {
//I will add conditional logic later
throw new Error('my custom error is thrown')
const test1 = 'I am test 1';
retur
我希望将metricsParams从componentA传递给componentB,当单击btn_genReport并触发generateReport()时。但它会抛出错误作为Uncaught TypeError: this.props.generateReport is not a function
componentA (metrics-report.jsx)
import React, { Component } from 'react';
import { Row, Col, Input, Collapsible, CollapsibleItem } from '
我有这个父组件:
import React from "react";
import ReactDOM from "react-dom";
import "./App.css";
import Instructions from "./components/instructions/instructions";
import Generate from "./components/button/button";
import View from "./components/view/view";
React是否提供了一种在正常流程之外呈现组件的标准方法?
我想在隐藏区域中呈现一个子元素,测量其尺寸,然后使用此信息更改组件的render方法返回的内容。尝试使用React.render时会抛出错误:
Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method
当我试图在react中导入一个组件时,我遇到了以下错误。
Uncaught TypeError: Cannot read property 'replaceChild' of null
at Function.replaceChildWithTree (index_bundle.js:4067)
at Object.dangerouslyReplaceNodeWithMarkup (index_bundle.js:21337)
at Object.dangerouslyReplaceNodeWithMarkup [as replaceNodeWithMarkup] (index
我正在使用redux应用程序在我的反应中尝试单元测试。因此,我需要测试连接的组件,不幸的是,我得到了这个错误:
无法读取未定义的属性“contextTypes”--我在单元测试中使用酶--这里是我的组件:
import React from 'react';
import TextFieldGroup from '../common/TextFieldGroup';
import validateInput from '../../server/validations/login';
import { co
当我尝试用react-i18next Trans组件内插一些React组件时,我会得到以下错误:
Uncaught Error: Trans(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
我是这样调用Trans组件的:
<Trans
t={l as TFunction}
defaul
在使用React创建了我的投资组合应用程序之后,我集成了使用GitHub页面所需的代码行。
该应用程序没有抛出错误,但除了背景色之外没有出现任何组件。
App.js代码
import './App.scss';
import { Route, Routes } from 'react-router-dom'
import Layout from './components/Layout';
import Home from './components/Home'
import About from './component