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 天內回覆