Cannot test with enzyme and jest
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript, react
调研方向
从 issue 中所示路径下的 ErrorDialog 组件及其测试开始,然后检查 Enzyme shallow 如何渲染导入的 rc-dialog 组件。复现所报告的文本输出,并确定是测试还是组件行为不正确。完成标准是测试能够可靠地观察到预期的消息和代码缺失,或者通过所需的项目更改澄清该 issue。
由索引模型根据 Issue 内容生成。
描述
Hi, I was trying to test the dialog component but it's not working.
Here is my component code
import Toast from '@/utils/Toast';
import PropTypes from 'prop-types';
import Dialog from 'rc-dialog';
import React from 'react';
import enhanceMessage from './enhanceMessage';
function ErrorDialog({ dismissError, error, breakoutFullText }) {
const { message, code, name } = error || {};
const enhancedMessage = enhanceMessage(message, code, breakoutFullText, name);
const styles = {
dialogContent: {
display: ' flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
};
if (code === 53105) {
Toast.info(breakoutFullText);
return true;
}
return error !== null ? (
<Dialog
title="Error"
className="main-dialog"
style={{ height: 200, width: 400, top: '20%' }}
onClose={() => dismissError()}
visible={error !== null}
destroyOnClose
animation="zoom"
maskAnimation="fade"
footer={
<button type="button" className="btn button" key="close" onClick={dismissError}>
OK
</button>
}>
<div style={styles.dialogContent}>
<h3>{name === 'NotFoundError' ? 'No camera found' : enhancedMessage}</h3>
<div>
{code && code !== 53105 && (
<pre>
<code>
Error Code:
{code}
</code>
</pre>
)}
</div>
</div>
</Dialog>
) : null;
}
Here is my test code
import ErrorDialog from '@/components/TwilioVideoMeeting/ErrorDialog/ErrorDialog';
import { shallow } from 'enzyme';
import Dialog from 'rc-dialog';
import React from 'react';
describe('Testing the ErrorDialog component', () => {
const message = 'Fake Error message';
it('should display error message but not error code is the later does not exist', () => {
const error = { message };
const wrapper = shallow(<ErrorDialog dismissError={() => {}} error={error} />);
expect(wrapper.find(Dialog).text()).toContain(message);
expect(wrapper.find('code').exists()).toBe(false);
});
});
It throws following error
the ErrorDialog component › should display error message but not error code is the later does not exist
expect(received).toContain(expected) // indexOf
Expected substring: "Fake Error message"
Received string: "< />"
Any Help would be appreciated
- 主要语言
- TypeScript
- 星标
- 454
- 派生
- 208
- 平均合并
- 1 小时 9 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react-component/dialog 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 38/100
react-component/dialog#467 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 25/100
react-component/dialog#450 ·
-
难度 3/5 1-2 天 新手友好度 35/100
react-component/dialog#429 · 1 条评论 ·
-
有没有安卓版啊未关闭
难度 5/5 一周以上 新手友好度 15/100
react-component/dialog#407 ·
-
难度 3/5 1-2 天 新手友好度 45/100
react-component/dialog#382 · 3 条评论 ·
查看 react-component/dialog 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Inbox: permission prompt (perm:) sessions appear as duplicate agents in the recipient picker and participants可能已有人在做 @Djiit 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
backnotprop/plannotator#4517 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
MoonshotAI/kimi-code#6000 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
OpenSlides/openslides-client#6768 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1-3 小时 新手友好度 90/100
modelcontextprotocol/modelcontextprotocol#3622 · 1 条评论 ·
维护者通常 1 天内回复