javascript - 如何在 __mocks__ 文件夹中开玩笑地使用手动模拟
问题描述
我正在尝试按照此处的建议使用手动模拟。Jest 似乎产生以下输出:
Error: Uncaught [Error: NewAnnotation(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.]
我的文件夹结构如下所示:
annotations
\ NewAnnotation
\__mocks__
\NewAnnotation.js
\NewAnnotation.js
\ AnnotationModal.js
\ AnnotationModal.test.js
我的 __mocks__\NewAnnotation
长相是这样的
import React from 'react';
export const NewAnnotation = () => (<button id="test">Hello World</button>);
export default NewAnnotation;
我的AnnotationModal.test.js
长相是这样的
/* eslint-disable */
import React from 'react';
import { shallow } from 'enzyme';
...
jest.mock('./NewAnnotation');
...
it(`this is an example test`, () => {
...
wrappedAnnotationModal.find("#test").simulate('click');
...
});
我错过了什么?
解决方案
推荐阅读
- android - ReactNative AppState 在调用时多次切换状态
- javascript - React 路由器正在更改 URL 但未正确加载网页
- c++ - 为什么没有调用预期的函数?我是否错误地理解了类型特征?
- r - R 中的 ifelse 语句不起作用 - 列结果不正确
- leaflet - 如何打开标记的分组
- html - VBA Excel解析HTML
- r - 在同一图中绘制 acf 和时间序列
- jmeter - 通过命令提示符运行时,我们可以打印计数器值 Jmeter 吗?
- r - 如何在特定行中删除带有 NA 的 dplyr 列?
- java - 如何实例化和使用包含其他对象的对象?