Free Sample
+ Collection

Jasmine JavaScript Testing

Paulo Ragonha

If you want to take your JavaScript coding to a new level of reliability and proficiency, this book is for you. Discover how to use Jasmine for unit testing whilst learning best practice for the whole JavaScript universe.
RRP $19.99
RRP $33.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781782167204
Paperback146 pages

About This Book

  • Learn the power of test-driven development while creating a fully-featured web application
  • Understand the best practices for modularization and code organization while putting your application to scale
  • Leverage the power of frameworks such as BackboneJS and jQuery while maintaining the code quality
  • Automate everything from spec execution to build; leave repetition to the monkeys

Who This Book Is For

This book is a must-have guide for web developers who are new to the concept of unit testing. It’s assumed that you have a basic knowledge of JavaScript and HTML.

Table of Contents

Chapter 1: Getting Started with Jasmine
JavaScript – the bad parts
Jasmine and Behavior-Driven Development
Downloading and first run
Chapter 2: Your First Spec
The Investment Tracker application
Jasmine basics and thinking in BDD
Setup and teardown
Nested describes
Understanding matchers
Chapter 3: Testing Frontend Code
Thinking in terms of components (Views)
The module pattern
Using HTML fixtures
Basic View coding rules
Testing Views with jQuery matchers
Chapter 4: Asynchronous Testing – AJAX
Setting up the Scenario
Writing the spec
Chapter 5: Jasmine Spies
The "bare" Spy
Spy an object's functions
Testing DOM events
Chapter 6: Light Speed Unit Testing
Jasmine Stubs
Chapter 7: Testing Backbone.js Applications
The Backbone model
Testing Backbone collections
Testing Backbone Views
Testing Backbone routers
Chapter 8: Build Automation
Headless testing with PhantomJS
Managing NPM dependencies
Chapter 9: Conclusion

What You Will Learn

  • Drive your application development entirely by tests
  • Organize your application code in modules with RequireJS
  • Create a fully-tested jQuery plugin
  • Solve problems and learn best practices for asynchronous testing
  • Use Stubs and Spies to perform quick unit testing
  • Test-drive a BackboneJS application
  • Optimize your JavaScript code to production
  • Master the power of tooling and automation with GruntJS
  • Run your tests on the cloud with Travis-CI

In Detail

From a little renegade scripting language to the de facto standard platform of today, JavaScript has become a universal language available in the widest range of devices; it is truly the 'write once, run everywhere’ language. However, as JavaScript applications become more complicated, testing and applying sustainable software engineering practices also become mandatory.

Jasmine JavaScript Testing is a practical guide to a more sustainable JavaScript development process. You will learn by example how to drive the development of a web application using tests and best practices.

This book is about becoming a better JavaScript developer. So, throughout the chapters, you will not only learn about writing tests, but also about the best practices for writing software in the JavaScript language. This book is about acknowledging JavaScript as a real platform for application development and leveraging all of its potential. You will also learn about tooling and automation and how to make your life easier and more productive.

You will learn how to create a sustainable codebase with the help of Jasmine. We will take a look at integrated testing (with a backend NodeJS server) and how you can speed this process up by faking AJAX requests. As you progress through the book, you will learn about the challenges of testing an application built on top of a framework and how you can prevent your application from suffering from dependency management hell. Also, since your applications need to get into production, you will learn about optimizing the code to reduce the number of requests the browser needs to make while loading your application.

With this book, you will learn everything you need to know to become a real professional in the ever-demanding JavaScript universe.


Read More