Most of time, we get used to use class name as a selector in the test.

But one problem for this is classname is used for styling, when we also use it for testing, we are not sure whether we can remove the classname whether it will break the tests.

Another thing is in React, we use CSS-in-JS approache, then class based test approach is no go.

The way we can use is by using "data-test":

<fieldset className="form-group">
<input
className="form-control form-control-lg"
type="email"
placeholder="Email"
data-test="email"
/>
</fieldset>
const emailField = rootNode.querySelector('[data-test="email"]')

Even better, we can make a help function:

const sel = id => `[data-test="${id}"]`
const emailField = rootNode.querySelector(sel('email'))

Blog

[Unit testing] data-test attr FTW的更多相关文章

  1. [Java Basics3] XML, Unit testing

    What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...

  2. Javascript单元测试Unit Testing之QUnit

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }           QUnit是一个基于JQuery的单元测试Uni ...

  3. [Unit Testing] AngularJS Unit Testing - Karma

    Install Karam: npm install -g karma npm install -g karma-cli Init Karam: karma init First test: 1. A ...

  4. C/C++ unit testing tools (39 found)---reference

    http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...

  5. Unit Testing a zend-mvc application

    Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...

  6. [Mockito] Spring Unit Testing with Mockito

    It is recommened to write unit testing with Mockito in Spring framework, because it is much faster w ...

  7. Unit Testing of Spring MVC Controllers: “Normal” Controllers

    Original link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...

  8. Java Unit Testing - JUnit & TestNG

    转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...

  9. 10 Unit Testing and Automation Tools and Libraries Java Programmers Should Learn

    转自:https://javarevisited.blogspot.com/2018/01/10-unit-testing-and-integration-tools-for-java-program ...

  10. Unit Testing with NSubstitute

    These are the contents of my training session about unit testing, and also have some introductions a ...

随机推荐

  1. jsp静态引入(<%@ include file=""%>) 乱码问题

    在web.xml中的web-app中加入这段话: <jsp-config> <jsp-property-group> <display-name>JSPConfig ...

  2. ArcGIS api for javascript——加载查询结果,单击显示信息窗口

    描述 本例在开始和地图交互前执行一个查询并加载结果.这允许用户点击任意郡县立即看到一个InfoWindow. QueryTask构造函数接受被查询的图层,即ESRI sample server上ESR ...

  3. ORA-12514: TNS: 监听程序当前无法识别连接描写叙述符中请求的服务

    不指定数据库能够正常连接: 指定数据库和使用PL/SQL Developer都出现错误: 在此说明一下我的环境:Oralce装的是64位的在使用PL/SQL Developer时曾出现过初始化错误,解 ...

  4. linux命令su与su-的差别

    su命令和su -命令最大的本质差别就是: su仅仅是切换了root身份.但Shell环境仍然是普通用户的Shell. 而su -连用户和Shell环境一起切换成root身份了. 仅仅有切换了Shel ...

  5. hdu(1069)——Monkey and Banana(LIS变形)

    题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...

  6. vim使用(二):经常使用功能

    1. vim经常使用功能 vim的经常使用功能.包含块的选择.复制,多文件的编辑.多窗体等功能. 2. vim块选择 块选择是将文档中的一块能够选择复制,粘贴,不用整行的处理. 按下 v , V . ...

  7. C++ 鼠标模拟程序

    关于鼠标模拟程序应用不算少见.在游戏外挂或者一些操作频繁位置确定的程序上应用往往有奇效. 比較旧的API是mouse_event,本人一開始也用这个在搞,只是后来才看到新的API在操作上更加统一.稍作 ...

  8. 使用LruCache和DiskLruCache来下载图片

    LruCache是一个非常好用的图片缓存工具: 主要做法是:滑动图片时将图片的bitmap缓存在LruCache<String, Bitmap>中,退出程序后将图片缓存进文件中.採用Dis ...

  9. Lesson 1 Basic Concepts: Part 1

    www.how-to-build-websites.com/basic-concepts/part1.php An introduction to domain names, web servers, ...

  10. centos7 zabbix3.4.6显示中文乱码问题

    工具 : winscp (Linux Windows 传输文件工具) 当部署完zabbix然后显示中文会出现如下图 然后此时先去windows的文字目录如 C:\Windows\Fonts 随便托个字 ...