In this lesson, we’ll add tests that finds a focused input. We’ll use Chrome’s dev tools from inside the Cypress runner to inspect the element and update our test to verify that the expected element is focused. We’ll see how Cypress can be used to test drive our application by creating a failing test and updating our application code to make it pass.

For exmaple in the todo app, when the page loaded, we want to test,

  • whether the input field is focused
  • whether the value of input filed is empty
  • whether the placeholder of the input field is "What needs to be done?"

The component code we have:

import React from 'react'

export default props =>
<form onSubmit={props.handleTodoSubmit}>
<input
type='text'
autoFocus
value={props.currentTodo}
onChange={props.handleNewTodoChange}
className="new-todo"
placeholder="What needs to be done?"/>
</form>

The test code:

form-input.spec.js:

describe('Form input', function () {
it('should has input filed auto focused when page loaded', function () {
cy.visit('/');
cy.focused()
.should('have.class', 'new-todo')
.and('have.attr', 'placeholder', 'What needs to be done?')
.and('be.empty');
});
});

API, Github

最新文章

  1. JavaBean和Map转换封装类
  2. support-v4不能查看源码
  3. PHP中的strtotime()对于31日求上个月有问题
  4. cdh 上安装spark on yarn
  5. hibernate--联合主键--annotation
  6. 4.vbs的循环,switch,判断等语句
  7. python 爬取天猫美的评论数据
  8. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之八 || API项目整体搭建 6.3 异步泛型仓储+依赖注入初探
  9. js前台计算两个日期的间隔时间(时间差)
  10. numpy交换列
  11. es6+的javascript拓展内容
  12. C语言变量的作用域和存储类型
  13. 关闭provider进程或者consumer进程后,会发生什么?
  14. lastlog
  15. 将本地的项目推送到github上
  16. 在VM克隆CENTOS以后,网卡的处理过程
  17. jdeveloper基础教程(中文版)
  18. XCODE的演变及使用经验分享
  19. 在vps上安装中文环境
  20. 《C++ Primer Plus》学习笔记 第1章 预备知识

热门文章

  1. PCB 一键远程桌面+RDP文件生成
  2. 阿里云centos系统上安装ftp
  3. POJ 1011 / UVA 307 Sticks
  4. JQuery 数据加载中禁止操作页面
  5. Go中的main函数和init函数
  6. Android_方向传感器
  7. js 图片轮播代码编辑
  8. 图像局部显著性—点特征(Fast)
  9. **ML : ML中的最优化方法
  10. Java RMI之HelloWorld经典入门案例