Jump to ratings and reviews
Rate this book

JavaScript Unit Testing

Rate this book
In Detail The largest challenge for many developers’ day to day life is ensuring the support of, and assuring the reach of, their product. With the ever increasing number of mainstream web browsers this is becoming a more difficult task for JavaScript coders. From the beginning, JavaScript Unit Testing will show you how to reduce the time you spend testing, and automate and ensure efficiency in guaranteeing your success. JavaScript Unit Testing will introduce and help you master the art of efficiently performing and automating JavaScript Unit tests for your web applications. Using the most popular JavaScript unit testing frameworks, you will develop, integrate, and automate all the tests you need to ensure the widest reach and success of your web application. Covering the most popular JavaScript Unit testing frameworks of today, JavaScript Unit Testing is your bible to ensuring the functionality and success of all of your JavaScript and Ajax Web Applications. Starting with Jasmine, you will also learn about, and use, YUITest, QUnit, and JsTestDriver, integrate them into your projects, and use them together to generate reports. Learn to automate these tools, make them work for you, and include the power of these tools in your projects from day one. Approach A practical, example-driven guide to using, automating, and integrating JavaScript Unit tests for the busy and conscientious JavaScript developer striving for excellence and success. Who this book is for JavaScript Unit Testing is a must have guide for every web developer, designer, architect, and JavaScript coder seeking to ensure the highest quality of their web applications and JS code. Knowledge of JavaScript is assumed.

192 pages, Kindle Edition

First published November 17, 2012

3 people are currently reading
24 people want to read

About the author

Hazem Saleh

12 books5 followers
Hazem Saleh has ten years of experience in Java EE, Mobile and Open Source technologies. He worked as a technical consultant for many clients in Europe (Sweden), North America (USA, Canada), South America (Peru), Africa (Egypt, Morocco, Zambia), and Asia (Qatar, Kuwait, KSA). He is an Apache MyFaces committer and a person who spent many years of his life writing open source software. Beside being the author of the "JavaScript Unit Testing" book, "Pro JSF and HTML5" book and the co-author of the "Definitive guide to Apache MyFaces" book, Hazem is also an author of many technical articles, a developerWorks contributing author and a technical speaker in both local and international conferences such as ApacheCon North America, Geecon, JSFDays, CON-FESS Vienna and JavaOne (San Francisco, Moscow, and Shanghai). Hazem is now working for IBM Egypt as an advisory software engineer. He is a member of the IBM Mobile Global CoC (Centre of Competency), and an IBM Certified Expert IT Specialist (L2).

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
5 (23%)
4 stars
0 (0%)
3 stars
11 (52%)
2 stars
4 (19%)
1 star
1 (4%)
Displaying 1 - 10 of 10 reviews
Profile Image for Piia Siintoharju.
33 reviews
November 2, 2019
Giving basic knowledge from unit testing and short introduction into four testing frameworks.

I would have liked that it would have been told more about the philosophy of unit testing, how to choose right testing framework and which are the differences between these presented testing frameworks - pros and cons.

I did not liked that too easy things were told again and again, especially at time it was told something from the code. The first thought after starting reading the book was that how old book I have bought...and hoped that it would have been published last year and not 2013.





Profile Image for Dmitry Sheiko.
8 reviews1 follower
April 9, 2013
As client-side application is getting more and more complex, front-end automated testing is more in demand. Before deployment we have to validate HTML according to given DTD, lint CSS and JavaScript, run performance tests, run unit-tests and do functional testing. Front-end unit testing has its quirks. We have to run tests on every browser and platform defined by our requirements. That is supposed to be automated and it's no easy task. There two widely spread approaches applicable in CI: Selenium Remote Control, which fires up any number of browsers, navigates to specific pages and performs tests and TestSwarm, where any number of clients listen for testing tasks on the server, perform test when requested and return results back to the server. As a budget solution, one can use Rhino with env.js, which emulates a the common browser environment.

Besides, JavaScript units don't often fit the model "assign function arguments and check the result code". Let's take a generic widget. It is being fired on some event (e.g. DOM is ready), gets references on required nodes by provided selectors, modifies DOM if necessary (render UI), subscribes handlers for specific events (button clicked, control value changed, key pressed). Thus to test a widget, we have to make a fixture emulating some initial state of DOM, check if the widget managed to find all the required nodes, check if it modified DOM as intended and trigger events to check handlers, provide mock end-points for Ajax-requests.

I recently laid the hands on, JavaScript Unit Testing book by Hazem Saleh. It gives excellent introduction into such testing frameworks as Jasmine, YUI Test Suit, QUnit, JsTestDriver. I would definitely add to this list Mocha , but whatever. Every framework is nicely covered and provided with test examples showing different cases: simple methods, asynchrononous methods, widget. What I'm unhappy with is the first chapter. I would begin with JavaScript unit-testing is a part of front-end automated testing, which is a part of Continuous Integration. The only introduction to CI the authors gives is a few-lines long obscure tip. Actually he provides examples of YUI Test / JsTestDriver integration with build tools, but it feels out of place to me, without a decent cover of CI. By the way, as far as I see, build-script examples are oriented on Windows. That's weird. I wouldn’t expect the majority of fronteers build on Windows.

The second thing I don't like about the chapter is that the author just after unit-testing/TDD introduction jumps to the example details and, by the way, the first framework following utilizes BDD. Thus, it would be just proper to explain first that the testing frameworks described below in the book based on *Unit and BDD styles (and QUnit is rather a custom style) and give some input regarding the styles.

What I found personally useful is the chapter about JsTestDriver. Of course I had heard about that one, but never bothered to go into details. The chapter puts it clear how one can exploit the solution. And it seems as a good alternative for cross-browser tests to Selenium RC (Selenium is still designed for functional testing) and Browserstack, which costs pretty money.
6 reviews
February 20, 2013
JavaScript Unit Testing it's a short book compared with other books published by PacktPub but the content quality hasn't been reduced. In any case I've missed information about other frameworks based on node.js that are becoming very popular like Mocha or CasperJS.

Another thing that could have improved is the application included with the book code. Since it's a book about JavaScript it should be an application developed with node.js and not with Java, further it would have been easier to run on your computer, since to run the included application you need to install Apache Tomcat.

Beyond these minor flaws that I mentioned, It's a highly recommended book, which includes a wealth of information and code from the most popular unit testing frameworks in the JavaScript community.

When you have finished reading it you will have a strong foundation to begin creating unit tests for your applications, which will improve your code and will optimize the time that you spend to modify existing applications.

More complete review at JuanjoFR.
4 reviews
July 30, 2014
My expectations might have been a bit off because I have read just a few comments before buying the book. I was expecting to read something like best practices and recommendations based on author's experience.

Instead of that, I basically got a framework X docs/reference listing available methods and example of usage. I liked that in first (Jasmine) chapter, even though I found the unnecessary explanations annoying pretty quickly (e.g. line of code like var client = app.getClient() with explanation like: Here we are creating a new instance of Client.) It would be fine here and there, but I had a feeling that I read almost every line two times (code + explanation).

Anyway, as I already mentioned.. the whole Jasmine chapter was good and it would help me start with testing. Unfortunately, the following chapters were basically the same, just with different framework, so reading was mostly boring until I got to using JSTD as a command line test runner and that was the end of the book.
2 reviews
March 13, 2013
I’ve just read the JavaScipt Unit Testing (http://www.packtpub.com/javascript-un...) and I found it very useful for professionals that need to implement or upgrade their strategy for Unit Testing.

The greatest gain, I believe, is the excellent explanation on how to use tools for Unit Testing like Jasmine, YUI, QUnit and JsTestDriver.
Great book!
Profile Image for Sebastian Gebski.
1,188 reviews1,340 followers
April 17, 2013
Plays its role. Presents basic features, focuses on critical needs (async call testing) and enables comparison between frameworks. Sadly it doesn't cover few interesting tools: like Selenium or Chutzpah.
Profile Image for Adomas Sliužinskas.
19 reviews10 followers
April 4, 2017
Jasmine, YUI test, QUnit & JsTestDriver readmes concatanated into a single book + a sample testing the same simple codedebase on each of them. Good for comparing the frameworks, but doesn't grasp anything beyond basics.
992 reviews24 followers
Read
July 16, 2015
Location: GG6 IRC, GG7 IRC, ND6 IRC
Accession No: DL027342-44
Profile Image for Donna.
157 reviews15 followers
did-not-finish
May 17, 2014
For work, but I'd rather be reading novels.
Displaying 1 - 10 of 10 reviews

Can't find what you're looking for?

Get help and learn more about the design.