[英]How can I write a unit test using jest, react, testing-library for this component?
I need to write unit tests using Jest and testing-library in a React typescript project.我需要在 React typescript 项目中使用 Jest 和 testing-library 编写单元测试。 And how can I create an ID for my component ErrorModal to use in my test?以及如何为我的组件 ErrorModal 创建一个 ID 以在我的测试中使用? I never wrote a test before.!我以前从来没有写过测试。! Thank you.谢谢你。
const ErrorModal = (props: {message: string}) => {
const { message } = props;
return (
<ErrorModalStyled>
<ErrorMessageStyled>{ message }</ErrorMessageStyled>
</ErrorModalStyled>
);
}
export default ErrorModal;
Read a little bit about jest.阅读一点关于笑话的内容。
In your case, try this.在你的情况下,试试这个。 https://jestjs.io/docs/tutorial-react#dom-testing https://jestjs.io/docs/tutorial-react#dom-testing
Basically, you will test if "message" is actually being rendered in your component by querying it.基本上,您将通过查询来测试“消息”是否真的在您的组件中呈现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.