Test-Driving JavaScript Applications: Rapid, Confident, Maintainable Code

Venkat Subramaniam

買這商品的人也買了...

相關主題

商品描述

Debunk the myth that JavaScript is not easily testable. Whether you use Node.js, Express, MongoDB, jQuery, AngularJS, or directly manipulate the DOM, you can test-drive JavaScript. Learn the craft of writing meaningful, deterministic automated tests with Karma, Mocha, and Chai. Test asynchronous JavaScript, decouple and properly mock out dependencies, measure code coverage, and create lightweight modular designs of both server-side and client-side code. Your investment in writing tests will pay high dividends as you create code that's predictable and cost-effective to change.

Design and code JavaScript applications with automated tests. Writing meaningful tests is a skill that takes learning, some unlearning, and a lot of practice, and with this book, you'll hone that skill. Fire up the editor and get hands-on through practical exercises for effective automated testing and designing maintainable, modular code.

Start by learning when and why to do manual testing vs. automated verification. Focus tests on the important things, like the pre-conditions, the invariants, complex logic, and gnarly edge cases. Then begin to design asynchronous functions using automated tests. Carefully decouple and mock out intricate dependencies such as the DOM, geolocation API, file and database access, and Ajax calls to remote servers.

Step by step, test code that uses Node.js, Express, MongoDB, jQuery, and AngularJS. Know when and how to use tools such as Chai, Istanbul, Karma, Mocha, Protractor, and Sinon. Create tests with minimum effort and run them fast without having to spin up web servers or manually edit HTML pages to run in browsers. Then explore end-to-end testing to ensure all parts are wired and working well together.

Don't just imagine creating testable code, write it.

What You Need:

A computer with a text editor and your favorite browser. The book provides instructions to install the necessary automated testing-related tools.

商品描述(中文翻譯)

揭開「JavaScript 不易測試」的迷思。無論您使用 Node.js、Express、MongoDB、jQuery、AngularJS 或直接操作 DOM,您都可以進行 JavaScript 測試驅動開發。學習使用 Karma、Mocha 和 Chai 編寫有意義、確定性的自動化測試。測試非同步 JavaScript、解耦並正確模擬依賴、測量程式碼覆蓋率,並創建輕量級的伺服器端和客戶端程式碼模組化設計。撰寫測試的投資將帶來高回報,因為您將創建可預測且成本效益高的程式碼。

使用自動化測試設計和編寫 JavaScript 應用程式。撰寫有意義的測試是一項需要學習、一些需要放棄以及大量實踐的技能,透過這本書,您將磨練這項技能。啟動編輯器,通過實際練習進行有效的自動化測試和設計易於維護、模組化的程式碼。

首先學習何時以及為何進行手動測試與自動驗證。將測試重點放在重要事項上,例如前提條件、不變量、複雜邏輯和棘手的邊界情況。然後開始使用自動化測試設計非同步函數。仔細解耦並模擬複雜的依賴,例如 DOM、地理位置 API、檔案和資料庫存取以及對遠端伺服器的 Ajax 呼叫。

逐步測試使用 Node.js、Express、MongoDB、jQuery 和 AngularJS 的程式碼。了解何時以及如何使用 Chai、Istanbul、Karma、Mocha、Protractor 和 Sinon 等工具。以最小的努力創建測試,並在不需要啟動網頁伺服器或手動編輯 HTML 頁面的情況下快速運行它們。然後探索端對端測試,以確保所有部分都能良好連接和運作。

不要只是想像創建可測試的程式碼,實際動手寫出來。

您需要:

一台電腦,配備文字編輯器和您喜歡的瀏覽器。本書提供安裝必要的自動化測試相關工具的說明。