首页 > 解决方案 > 如何在 __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');
  ...
});

我错过了什么?

标签: javascriptreactjsunit-testingjestjsenzyme

解决方案


推荐阅读