Rails 5 Test Prescriptions 第10章 Unit_Testing JavaScript(新工具,learn曲線太陡峭,pass)

來源:互聯網
上載者:User

標籤:改進   3.0.0   json   rails   esc   rail   column   元素   環境   

對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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.