对Js的单元测试是一个大的题目。作者认为Ruby的相关测试工具比Js的测试工具更灵活

大多数Js代码最终是关于响应用户的行为和改变DOM中的元素

没有什么javascript的知识点。前两节用了几个新的测试工具,和大量配置,暂时pass.

  • setup js Unit-tests
  • writing a Sample test
  • Tdd in Js
  • jasmine matchers
  • testing ajax calls
  • using testdouble.js
  • connecting the js to the server code

Setting Up JavaScript Unit Tests

Webpack的配置很复杂,虽然rails团队已经做了改进,有时仍需要挖掘细节。

本章使用:

Karma test runner: 从命令行运行,执行测试,和微博趴窗口良好兼容

Jasmine: 一个测试的工具,作者喜欢它的syntax。

TestDouble package:

命令:加载相关的模块:

yarn add jasmine jasmine-core karma karma-chrome-launcher karma-jasmine karma-mocha-reporter karma-sourcemap-loader karma-webpack testdouble testdouble-jasmine --dev

解释:

使用Yarn package manager来管理独立的JS。使用Yarn来加载这些modules。

--dev命令增加这些模块到package.json中的独立的section 。(就是说这些模块只在development环境下使用,都是用于测试的) 标签是"devDependencies"

  "devDependencies": {
    "jasmine": "^3.1.0", 写代码的库
    "jasmine-core": "^3.1.0", 写代码的库
    "karma": "^2.0.2", command-line program 
    "karma-chrome-launcher": "^2.2.0", 让karma在Chrome中运行测试
    "karma-jasmine": "^1.1.2", 接口
    "karma-mocha-reporter": "^2.2.5",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^3.0.0", 让karma使用webpack
    "testdouble": "^3.8.1", mock object package
    "testdouble-jasmine": "^0.2.1", 两者的集成。
    "webpack-dev-server": "2.11.2"
  }

再运行:

$ yarn global add karma-cli

所以模块已经加载了。

Rails 5 Test Prescriptions 第10章 Unit_Testing JavaScript(新工具,learn曲线太陡峭,pass)的更多相关文章

  1. Rails 5 Test Prescriptions 第10章 Testing for Security

    Web 安全是一个可怕的主题.所有的你的程序都依靠密码学,代码超出了你的控制. 尽管如此,你还是可以控制部分网页安全 --所有的logins和access checks和injection error ...

  2. Rails 5 Test Prescriptions 第9章 Testing-JavaScript: Integration Testing,❌挂一个问题webpacker::helper

    使用Capybara进行JS的集成测试 谈论驱动 让测试通过 Webpack in Development Mode Js设计 是用户在网页上有好的体验的重要因素. 尽管如此,许多网页不测试JS. 部 ...

  3. Rails 5 Test Prescriptions 第11章其他部分的测试。

    Routes✅ Helper Methods✅ Controllers and Requests✅ Simulating Requests⚠️,看之前的博客 What to Expect in a R ...

  4. Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber

    Capybara:  A complete reference is available atrubydoc.info. 集成测试就是把局部的程序组合起来测试. 端到端测试是一个特殊的集成测试,覆盖了 ...

  5. Rails 5 Test Prescriptions 第6章Adding Data to Tests

    bcreate the data quickly and easily.考虑测试运行的速度. fixtures and factories.以及下章讨论的test doubles,还有原生的creat ...

  6. Rails 5 Test Prescriptions 第5章 Testing Models

    Rails,model层包含业务逻辑和储存逻辑.其中储存逻辑被ActiveRecord处理. 在model中,不是每件事都必须是ActiveRecord对象.model layer可以包含各种服务,对 ...

  7. Rails 5 Test Prescriptions 第4章 什么制造了伟大的测试

    伴随着程序成长,测试变长,复杂性增加,如何更高效的写测试,对以后开发不会造成麻烦. 测试本身没发被测试,所以一定要清楚,可控.不要加循环,不要过于复杂的自动编程. Cost and Value 成本和 ...

  8. Rails 5 Test Prescriptions 第3章Test-Driven Rails

    本章,你将扩大你的模型测试,测试整个Rails栈的逻辑(从请求到回复,使用端到端测试). 使用Capybara来帮助写end-to-end 测试. 好的测试风格,包括端到端测试,大量目标明确的单元测试 ...

  9. Rails 5 Test Prescriptions 第7章 double stub mock

    https://relishapp.com/rspec/rspec-mocks/v/3-7/docs/basics/test-doubles 你有一个问题,如果想为程序添加一个信用卡程序用于自己挣钱. ...

随机推荐

  1. sublime3095-注册码下载安装

    链接:http://pan.baidu.com/s/1hqejFKS 下载地址:下载 提取密码:egh5 ----- BEGIN LICENSE ----- Andrew Weber Single U ...

  2. 170803、springboot jar包启动提示没有主清单属性

    问题:SpringBoot打包成jar后运行提示没有主清单属性 解决: 补全maven中的bulid信息 <plugin> <groupId>org.springframewo ...

  3. Python量化教程 常用函数

    # -*- coding: utf-8 -*- # @Author: fangbei # @Date: 2017-08-26 # @Original: price_str = '30.14, 29.5 ...

  4. 快递API接口

    快递100        

  5. Excel 26机制转换

    [问题描述] 在Excel中,列的名称是这样一个递增序列:A.B.C.….Z.AA.AB.AC.….AZ.BA.BB.BC.….BZ.CA.….ZZ.AAA.AAB….我们需要将上述列名序列和以下自然 ...

  6. CCScene,CCLayer,CCSprite,CCDirector

    一.CCScene : 游戏中不同的画面可以用不同的场景展示出来,大致的可以分为以下的几类场景: 1. 展示类场景.游戏开场画面,游戏简介,胜利以及失败提示,帮助. 2. 选择类场景.主菜单,游戏设置 ...

  7. mysql误删表,无备份

    mysql误删表,无备份 1.操作步骤:https://blog.csdn.net/u011277123/article/details/78018513?tdsourcetag=s_pctim_ai ...

  8. Windows版本搭建安装React Native环境配置

    1 安装Chocolatey 打开cmd黑窗口 @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-obje ...

  9. 7.如何将python脚本打包为exe形式

    先安装pyinstaller,pip install pyinstaller 然后 pyinstaller -F combine.py打包即可

  10. Callable 和Runnable

    1:Callable ,方法调用会有返回值. private void callableTest throws ExecutionException, InterruptedException { E ...