testing-library中的user-event有多少种,分别怎么用

时间: 2024-10-18 17:17:57 浏览: 3
`testing-library/user-event`是一个JavaScript库,主要用于模拟用户在浏览器中的交互行为,比如点击、输入、滚动等,以便在单元测试中验证组件的行为。它主要包括以下几个核心模块: 1. `click`: 用于触发鼠标点击事件。例如: ```javascript userEvent.click(element); ``` 2. `type`: 用于模拟键盘输入,可以输入单个字符或字符串。例如: ```javascript userEvent.type(textInput, 'Hello, World!'); ``` 3. `press`: 可以模拟键盘按键,如`userEvent.press('Enter')`。 4. `focus`: 设置元素聚焦。例如: ```javascript userEvent.focus(inputElement); ``` 5. `blur`: 移除元素聚焦。例如: ```javascript userEvent.blur(inputElement); ``` 6. `scroll`: 模拟滚动操作。例如: ```javascript userEvent.scroll(container, { top: 100 }); ``` 7. `dragAndDrop`: 拖放元素到另一个元素上。例如: ```javascript userEvent.dragAndDrop(sourceElement, targetElement); ``` 8. `submit`: 对表单元素进行提交。通常配合其他动作一起使用,比如先点击按钮再提交表单。
阅读全文

相关推荐

Also create a ControllerCreate class that extends Controller.The create method takes as arguments the name of a new library user, a number of books (as a string), and an integer representing the role of user to create (where the integer 0 means a lender and the integer 1 means a borrower). The create method of the controller then transforms the book number from a string to an integer (using the Integer.parseInt static method), creates an object from the correct class (based on the role specified by the user input: lender or borrower) and calls the addUser method of the library to add the new user object to the library. • If no exception occurs then the create method of the controller returns the empty string. • If the constructor of the Borrower class throws a NotALenderException then the create method of the controller must catch this exception and return as result the error message from the exception object. • If the parseInt method of the Integer class throws a NumberFormatException (because the user typed something which is not an integer) then the create method of the controller must catch this exception and return as result the error message from the exception object. Modify the run method of the GUI class to add a ViewCreate view that uses a ControllerCreate controller and the same model as before (not a new model!) Do not delete the previous views. Note: if at the end of Question 7 you had manually added to your library (model object) some users for testing, then you must now remove those users from the run method of the anonymous class inside the GUI class. You do not need these test users anymore because you have now a graphical user interface to create new users! Run your GUI and check that you can correctly use the new view to create different users for your library, with different types of roles. • Check that, when you create a new user, the simple view is automatically correctly updated to show the new total number of books borrowed by all users. • Also use the “get book” view to check that the users are correctly created with the correct names and correct number of books. • Also check that trying to create a borrower with a negative number of books correctly shows an error message. Also check that trying to create a user with a number of books which is not an integer correctly shows an error message (do not worry about the content of the error message). After you created a new user, you can also check whether it is a lender or a borrower using the “more book” view to increase the number of books of the user by a big negative number: • if the new user you created is a lender, then increasing the number of books by a big negative value will work and the number of books borrowed by the user will just become a larger value (you can then check that using the “get book” view); • if the new user you created is a borrower, then increasing the number of books by a big negative value will fail with an error message and the number of books borrowed by the user will not change (you can then check that using the “get book” view). 完成符合以上要求的java代码

最新推荐

recommend-type

Owasp Testing Guide v4 中文版.pdf

总之,《Owasp Testing Guide v4 中文版》是Web应用安全测试领域的重要参考资料,它提供了一套系统性的测试框架,有助于提升安全测试的专业性和效率,保障Web应用免受各种安全威胁。无论是初学者还是经验丰富的安全...
recommend-type

敏捷测试中的User Story 详解

User Story 的应用对于使用任何敏捷开发方法的软件开发人员、测试人员、分析人员和管理者都是极其有价值的。敏捷开发团队的彻底审查和努力实践证实了 User Stories 应用提供了一种节省时间、减少重复工作、并且能够...
recommend-type

软件测试报告-大作业-图片服务器项目。

在本软件测试报告中,学生将参与一个名为“图片服务器项目”的课程设计,目标是全面测试Web网站的各个层面。报告详细介绍了整个测试过程,包括测试计划、实施步骤以及使用到的各种工具和技术。 首先,课程设计内容...
recommend-type

全国地级市经济高质量发展发展指数(2000-2021年)-最新出炉.zip

全国地级市经济高质量发展发展指数(2000-2021年)-最新出炉.zip
recommend-type

Postman安装与功能详解:适用于API测试与HTTP请求

资源摘要信息:"Postman是一款广受欢迎的HTTP客户端应用程序,主要用于API测试。本资源提供了Postman的安装文档和安装包,供学习使用。Postman支持HTTP、HTTPS、SOAP等多种协议,具备数据导入导出、请求参数化、断言、测试脚本编写等强大功能,极大地提升了开发和测试人员的工作效率。 Postman的适用人群非常广泛,包括但不限于前端开发人员、后端开发人员、测试人员和运维人员。使用Postman可以方便地发送各种类型的HTTP请求,如GET、POST、PUT、DELETE等,并对API进行响应时间和性能测试,验证API的正确性与可靠性,实现自动化测试以及持续集成,并能导出测试数据和请求模板。 Postman作为一款免费的工具,用户可以通过其官方网站下载适用于Windows、Mac和Linux操作系统的安装包。该软件安装过程简单,运行高效,并且拥有直观的用户界面,使学习和使用变得简单便捷。此外,Postman还拥有详尽的文档资源和活跃的社区支持,用户在使用过程中遇到问题可以快速获得帮助,同时也能学习到更多的使用技巧和最佳实践。 安装包文件列表中包含了Postman的安装程序和相关的帮助文档,为用户提供了完整的安装和学习资源,确保用户能够顺利完成安装并迅速掌握使用方法。"
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

C++自定义异常深度剖析:原理揭示与最佳实践指南

![C++的自定义异常(Custom Exceptions)](https://www.delftstack.com/img/Cpp/feature image - cpp custom exception.png) # 1. C++异常处理基础 ## C++异常处理概述 异常处理在C++程序中扮演着至关重要的角色,用于处理在程序执行过程中出现的非正常情况,比如文件读写错误、除以零的运算错误等。通过异常处理,开发者能够以一种结构化的方式管理错误,提高程序的健壮性和可维护性。 ## 关键概念:try, catch 和 throw C++中,异常处理涉及到三个关键词:`try`、`catch`
recommend-type

依赖注入顺序问题,A,B两个类都实现了某个接口,如何确保A类优先B类加载

在Spring框架中,依赖注入的顺序通常由Spring IoC容器控制,并不是按照类声明的顺序进行。如果你想要保证A类优先于B类加载并且使用,可以考虑以下几种策略: 1. **构造函数注入**: 将`A`类作为`B`类构造函数的参数。这样,当你创建`B`类的对象时,实际上也是间接地创建了`A`类的对象,进而保证了`A`类的初始化在前。 ```java @Service class BImpl implements MyInterface { private final A a; @Autowired public BImpl(A a) { this
recommend-type

Dart打造简易Web服务器教程:simple-server-dart

资源摘要信息:"simple-server-dart是一个使用Dart语言编写的简单服务器端应用。通过阅读文档可以了解到,这个项目主要的目标是提供一个简单的Web服务器实例,让开发者能够使用Dart语言快速搭建起一个可以处理HTTP请求的服务器。项目中的核心文件是server.dart,这个文件包含了服务器的主要逻辑,用于监听端口并响应客户端的请求。该项目适合那些希望学习如何用Dart语言进行服务器端开发的开发者,特别是对Dart语言有基础了解的用户。" 知识点详述: 1. Dart语言简介 - Dart是谷歌开发的一种编程语言,旨在提供一种简洁、面向对象的语言,能够用于客户端(如Web和移动应用)、服务器端以及命令行应用的开发。 - Dart设计之初就考虑到了高性能的需求,因此它既能在开发阶段提供快速的开发体验,又能编译到高效的机器码。 - Dart有自己的运行时环境以及一套丰富的标准库,支持异步编程模式,非常适合构建需要处理大量异步任务的应用。 2. Dart在服务器端的运用 - Dart可以用于编写服务器端应用程序,尽管Node.js等其他技术在服务器端更为常见,但Dart也提供了自己的库和框架来支持服务器端的开发。 - 使用Dart编写的服务器端应用可以充分利用Dart语言的特性,比如强类型系统、异步编程模型和丰富的工具链。 3. 项目结构与文件说明 - 项目名称为simple-server-dart,意味着这是一个设计来展示基本服务器功能的项目。 - 在提供的文件列表中,只有一个名为simple-server-dart-master的压缩包,这表明这个项目可能是一个单一的主干项目,没有额外的分支或标签。 - 文件列表中提到的"server.dart"是该项目的主要执行文件,所有服务器逻辑都包含在这个文件中。 4. 运行服务器的基本步骤 - 根据描述,要运行这个服务器,用户需要使用Dart SDK来执行server.dart文件。 - 通常,这涉及到在命令行中输入"dart server.dart"命令,前提是用户已经正确安装了Dart SDK,并且将项目路径添加到了环境变量中,以便能够从任意目录调用dart命令。 - 运行服务器后,用户可以通过访问绑定的IP地址和端口号来测试服务器是否正常运行,并且能够处理HTTP请求。 5. Web服务器构建基础 - 构建Web服务器通常需要处理网络编程相关的问题,如监听端口、解析HTTP请求、处理会话和构建响应。 - 服务器通常需要能够处理GET、POST等HTTP方法的请求,并且根据请求的不同返回适当的响应内容。 - 在本项目中,服务器的具体功能和实现细节将会通过阅读server.dart文件来了解。 6. Dart SDK与工具链 - 开发者在编写Dart代码后,需要通过Dart编译器将代码编译成不同平台上的机器码。Dart SDK提供了一个命令行工具,可以编译和运行Dart程序。 - Dart还提供了pub包管理器,用于管理项目依赖和下载第三方库。这对于服务器端项目来说同样重要,因为开发者可能需要使用到各种开源库来辅助开发。 7. 异步编程模式 - Dart语言内置了对异步编程的支持。在Web服务器编程中,异步操作是非常常见的,例如处理I/O操作时,程序需要等待磁盘或网络响应而不能阻塞其他操作。 - Dart使用Future和Stream来处理异步编程,开发者可以通过这些工具来构建非阻塞的异步代码逻辑。 总结,simple-server-dart项目是一个展示如何使用Dart语言创建简单Web服务器的示例。它强调了Dart在服务器端编程方面的可能性,并且为那些对Dart有兴趣的开发者提供了一个实践的起点。通过本项目的探索,开发者能够获得Dart服务器端编程的初步经验,并且能够将所学知识应用到更复杂的项目中。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依