我用创建了一个基本的NextJS应用程序,然后添加了用于测试的Jest。但是,我得到的错误是“在测试中对图像的更新没有包装在act(.)中”在我的Jest测试中。这似乎与渲染后的NextJS更新的图像组件有关,但我不太确定用它进行测试的最佳方法是什么。我在这里包含了Jest测试和组件中有问题的部分:
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import styles from '../s
尝试编写一个测试来确保handleClick()被调用,但我得到了以下错误:TypeError: Cannot read property '_isMockFunction' of undefined。
下面是我正在测试的组件(主要是),以及我正在使用Jest和Enzyme运行的测试代码。
import React from 'react';
import localize from '../data/Localize';
import translations from './translations';
class Cate
当我将这段代码添加到代码中时,我的Jest测试就会中断:
import 'promise-polyfill/src/polyfill';
Jest encountered an unexpected token
This 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 Babel config, it will use that t
我有一个现有的项目,使用React Native和Expo。目前,该应用程序运行良好。我正在尝试将Jest集成到项目中。jest中的基本"true=true“测试通过并运行时没有错误。但是,当我尝试使用ES6术语运行任何代码时,出现以下错误: FAIL screens/__tests__/home.test.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file whi
我刚刚开始为React JS做一些单元测试--使用Jest / enzyme。我想知道哪种测试(格式)更有用,更适合用于未来的测试。这是我目前正在做的两个不同的测试。
单元测试1:我的大部分测试都是基于这个设置的编写的
import React from 'react';
import Enzyme from 'enzyme';
import { shallow} from 'enzyme';
import EditWorkflow from './EditWorkflow';
import Adapter from 'e
我有一个React类,我们称它为A。我正在对它运行一个jest测试,但我一直收到
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
在我正在做的React类中:export class A extends Component ..
在我正在执行的jest测试文件中:import { A } from './A.js'
当我运
我正在尝试使用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
我有一个使用useEffect的组件,它使用api调用redux操作,称为props.getPostsInit();。
我如何测试这个,现在我得到一个错误,它没有调用getPostsInit道具
● <Dashboard/> › Should execute getPostsInit
expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
仪表板
function Dashboard(props: das
我使用的是react-ga v2.5.7,为此我更新了react-redux v7.0.2,我使用的是jest v24.7.1 我在testMode中设置了react-ga,但它在我的jest.setup.js中被模拟了。但是每次我运行我的测试时,我总是遇到同样的问题,大多数测试都因为一些奇怪的原因而失败: Test suite failed to run
Cannot find module '@icons/material/CheckIcon' from 'SwatchesColor.js'
However, Jest was able
我构建React应用程序已经有一段时间了,所以我想做一个React组件库。我一直在阅读有关方法的文章,并采用了一种方法,在这种方法中,您可以使用Webpack和Babel来绑定而不使用React,因为如果您不这样做,将会出现错误,因为将导入两个版本的React (一个在组件库中,一个在应用程序中)。无论如何,我有一个Jest安装文件,其中包含以下内容: import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
configure({ adapter: ne