我在一个@storybook/react项目中使用create-react-app 6。
对于我所有的存储/对象,我都有成千上万的测试和模拟,等等。
这些模拟使用了jest.fn()。
我想在我的故事故事中重复使用这些模仿,但是它说的是jest is not defined,这是有意义的。
我想知道,在运行故事书时,是否有一种简单的方法可以在全球范围内提供笑话。
目前,我正在使用的每个模拟文件中添加import jest from 'jest-mock',但我想知道是否有更好的解决方案。
示例:
test.stories.tsx
import React from 'r
我构建React应用程序已经有一段时间了,所以我想做一个React组件库。我一直在阅读有关方法的文章,并采用了一种方法,在这种方法中,您可以使用Webpack和Babel来绑定而不使用React,因为如果您不这样做,将会出现错误,因为将导入两个版本的React (一个在组件库中,一个在应用程序中)。无论如何,我有一个Jest安装文件,其中包含以下内容: import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
configure({ adapter: ne
我有一个React站点(使用TypeScript和Webpack),它使用FortAwesome的react-fontawesome包来呈现图标。该包的导入方式如下:
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
在使用酶添加Jest测试时,任何使用包含对FontAwesomeIcon的引用的组件的测试都会失败,并显示以下内容:
Warning: React.createElement: type is invalid -- expected a string (for built-in
compon
我试图对react组件和测试抛出运行一个简单的ReferenceError: React is not defined.和enzyme测试。我遵循了关于jest和react测试的所有简单教程,但它们都导致了相同的异常。我使用了npm test,结果与yarn test相同,React未定义。我很困惑。任何帮助都将不胜感激。
Checkbox.test.jsx:简单测试
import { shallow } from 'enzyme';
import sinon from 'sinon';
import Checkbox from './Checkbox
我正在尝试遵循https://jestjs.io/docs/en/api中关于导入全局变量的建议,即: However, if you prefer explicit imports, you can do import {describe, expect, it} from '@jest/globals'. 不过,它不起作用。我在两个测试文件的顶部添加了import,当我运行jest时,两个测试套件都失败,并显示消息"Do not import @ Jest /globals not of the Jest test environment“。 我还在eslint
我安装了browser-image-compression,作为其功能的一部分,它创建了一个Worker。现在,当我运行jest测试时,我得到以下错误: Test suite failed to run
ReferenceError: Worker is not defined 没有连接到使用浏览器图像压缩的函数的测试。 package.json中的脚本部分包含以下两行 "test": "react-scripts test",
"test:ci": "cross-env CI=true react-scripts test"
我刚开始开玩笑和反应,我只是安装了所需的软件包,以使其运行。现在,我想向已经创建的React组件添加一些测试。我用的是Jest。在运行npm run test命令时,根据jest文档,它会引发以下错误:
D:\Users\rdmello\Documents\linqin_Updated12-2\trunk\WebReporting>npm
run
test
> react@1.0.0 test D:\Users\rdmello\Documents\linqin_Updated12-
2\trunk\WebReporting
> jest
FAIL S
我正试图取笑一个新的react-native项目。但是,当我运行npm run test时,我会得到以下错误ReferenceError: __DEV__ is not defined。关于这个问题,我已经看过无数的Github问题和Stack溢出帖子,但是没有一个建议在我的案例中有效。
这是我的jest.config.js文件:
module.exports = {
transformIgnorePatterns: [
"node_modules/(?!(react-native|react-native-button|react-native-video)/)
我正在使用react-native init创建一个react-native项目。我正在为SQLite绑定使用库。
我有一个DbConnector.jest-test.js单元测试文件。内容是
import DbConnector from '../app/components/DbConnector.js';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correc
我正在尝试学习React,但是这个'Container‘没有定义,我不知道为什么会出现这个错误,即使我在课程中做了所有的事情 这是App.js import React from "react";
import { Row } from "reactstrap";
import CategroyList from "./CategroyList";
import Navi from "./Navi";
import ProductList from "./ProductList";
function A
我尝试了许多将jest导入到我的项目中的方法。所有这些都会导致我的应用程序在访问localhost:3000时显示空白屏幕,即使所有语句都会导致app编译(导入一行会导致应用崩溃):
import { mocked } from "ts-jest"
import { mocked } from '@jest/globals'
import { jest } from 'ts-jest'
import { jest } from '@jest/globals'
App崩溃时会出现以下错误:
VM551:2 Uncaught R
我使用的是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
我正在尝试用Jest测试一个承诺,当它在浏览器中运行时,这段代码会按照它应该执行的方式执行。不过,我想开始为它编写测试。
class ListCollection {
constructor() {
this.items = new Array();
}
addItem(string) {
const addItemPromise = new Promise(
function (resolve, reject) {
// set up async getting like a XMLHttpRequest
setTi
运行Jest时收到以下错误
Cannot find module 'src/views/app' from 'index.jsx'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (src/index.jsx:4:12)
index.jsx
import AppContainer from 'src/views/app';
package.json
"jest"
我正在尝试使用React addons-test-utils来浅呈现一个React组件(ComponentA),以便我可以对它进行快照。
A项进口构成部分B。
组件B导入'jquery‘和’jquery/ui/widget/draggable‘,这将导致在Jest:jQuery is not defined下运行测试时出错。
我尝试使用package.json中的一个package.json属性导入jquery和jquery,但只取得了部分成功。我了解到了这个错误:Cannot read property 'mouse' of undefined
由于我只是想要一个浅浅
我是新来reactJS的。我用Jest测试我的组件RegisterForm。
我是已经测试过的模拟组件(例如PasswordField)。因此,我模拟了它,但我有一个错误出现:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined i