[Unit testing] data-test attr FTW
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'))
[Unit testing] data-test attr FTW的更多相关文章
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- Javascript单元测试Unit Testing之QUnit
body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } QUnit是一个基于JQuery的单元测试Uni ...
- [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 ...
- C/C++ unit testing tools (39 found)---reference
http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...
- Unit Testing a zend-mvc application
Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...
- [Mockito] Spring Unit Testing with Mockito
It is recommened to write unit testing with Mockito in Spring framework, because it is much faster w ...
- Unit Testing of Spring MVC Controllers: “Normal” Controllers
Original link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...
- Java Unit Testing - JUnit & TestNG
转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...
- 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 ...
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
随机推荐
- Win10 + YOLOv3训练VOC数据集-----How to train Pascal VOC Data
How to train (Pascal VOC Data): Download pre-trained weights for the convolutional layers (154 MB): ...
- ArcGIS api for javascript——地图配置-定制平移动画
描述 本例展示了当用户点击平移按钮时如何定制地图的动画.panDuration和panRate是Dojo动画属性,可以分别确定动画的duration和帧刷新的rate.这些属性的单位都是毫秒,panD ...
- CSS3 实现RSS图标
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS3 实现RSS图标&l ...
- DMA在FPGA的应用之我见
首先,来做一个简单的实验,利用DMA来实现on-chip-memory和SRAM之间的传输,同时也在做一个关于SRAM不同地址之间的传输. 一.硬件设计 1.首先设计自己的SOPC结构,包括CPU.j ...
- HDU 4358 Boring counting dfs序+莫队算法
题意:N个节点的有根树,每个节点有一个weight.有Q个查询,问在以u为根的子树中,有恰好出现了K次的weight有多少种. 这是第一次写莫队算法,之前也只是偶有耳闻. 看了别人的代码打的,还是贴上 ...
- apache-maven-3.0.4-bin.zip
http://zhidao.baidu.com/share/2a8974fd1546ef5f11ad9cccb3cabf88.html apache-maven-3.0.4-bin.zip
- vue 实现文本域还剩多少字符
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 解析position定位
关于position定位(所有主流浏览器都支持 position 属性),大家会联想到relative和absolute,下面我就讲一下relative和absolute分别是相对于谁进行定位的? 在 ...
- this对象的理解
(回答一:) (1).js的this指向是不确定的,也就是说是可以动态改变的.call/apply 就是用于改变this指向的函数,这样设计可以让代码更加灵活,复用性更高 (2).this 一般情况下 ...
- 【Uva 1629】 Cake slicing
[Link]: [Description] 给你一个n*m的格子; 然后里面零零散散地放着葡萄 让你把它切成若干个小矩形方格 使得每个小矩形方格都恰好包含有一个葡萄. 要求切的长度最短; 问最短的切割 ...