gpt4 book ai didi

reactjs - React-Testing 库未在快照中呈现 Material-UI 对话框

转载 作者:行者123 更新时间:2023-12-04 16:25:20 24 4
gpt4 key购买 nike

export default function CommentDialog(props) {
const {
approvalValue,
handleSubmit,
handleDialog,
handleChange,
handleApprovalChange,
value,
characterCount,
maxCharacterValue,
} = props;

const { handleOpen, handleClose, open } = handleDialog;
const classes = useStyles();

return (
<>
<AddCommentButton onClick={handleOpen} />
<Dialog fullWidth onClose={handleClose} aria-labelledby="customized-dialog-title" open={open}>
<DialogTitle id="customized-dialog-title" onClose={handleClose}>
Please select an outcome for this Targeting Request
</DialogTitle>
<RadioGroup
aria-label="quiz"
name="quiz"
value={approvalValue}
onChange={handleApprovalChange}
className={classes.radioButtons}
>
<FormControlLabel value="Approved" control={<Radio color="primary" />} label="APPROVE" />
<FormControlLabel value="Denied" control={<Radio color="secondary" />} label="DENY" />
</RadioGroup>
<DialogContent>
<MarkdownEditor
id="comment-markdown"
error={characterCount >= maxCharacterValue && MAX_CHARACTER_MSG}
value={value}
onChange={handleChange}
label="Please enter your comments"
/>
</DialogContent>
<Divider />
<DialogActions className={classes.bottomDiv}>
<TextField
disableUnderline
id="max-character-counter"
label="Maximum Characters"
InputProps={{
readOnly: true,
}}
value={`${characterCount}/${maxCharacterValue}`}
disabled
error={characterCount >= maxCharacterValue && MAX_CHARACTER_MSG}
/>
<div>
<Button
disabled={(approvalValue === 'Denied' && value === '') || approvalValue === ''}
onClick={handleSubmit}
color="primary"
>
Submit
</Button>
<Button onClick={handleClose} color="primary">
Cancel
</Button>
</div>
</DialogActions>
</Dialog>
</>
);
}
it('onChange called on type in markdown box', async () => {
const { container } = render(<CommentDialog {...modifiedProps} />);
expect(container).toMatchSnapshot();
});
预期行为:呈现按钮和对话框
实际行为:单独呈现按钮。
此渲染仅渲染组件顶部的按钮。从 handleDialog 传播的 open 值为 true,因此对话框应该是打开的,但在我的快照上它只显示按钮。
我不认为这与任何异步和它在加载之前触发有关。我使用 JSDOM 16 和 Jest 来运行测试。

最佳答案

您只需要更换 containerbaseElement .它可以是这样的:

it('onChange called on type in markdown box', async () => {
const { baseElement } = render(<CommentDialog {...modifiedProps} />);
expect(baseElement).toMatchSnapshot();
});
然后你会在 body 内部看到你的模态

关于reactjs - React-Testing 库未在快照中呈现 Material-UI 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65683893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com