Book Image

Jasmine Cookbook

By : Munish Kumar
Book Image

Jasmine Cookbook

By: Munish Kumar

Overview of this book

Table of Contents (16 chapters)
Jasmine Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing Jasmine tests for exceptions


In this recipe, you will learn to write Jasmine tests for JavaScript exceptions using the toThrow() and toThrowError() matchers. Also, you will learn how to write Jasmine tests to validate user-defined messages.

To write the Jasmine test for Exceptions, let's assume that you are developing an application for <ABC> company. Currently, you are developing an error handling module, which handles user-defined or system errors.

"As a JavaScript developer, I want to handle all the errors and validate error messages so that the end user should not get stuck during any process."

Let's consider some scenarios in the current context, that is, all the system and user-defined errors should be handled throughout the application:

  • Scenario-1: Error should be thrown on any unexpected behavior or malfunction.

  • Scenario-2: Error messages should be consistent throughout the application.

How to do it...

You need to perform the following steps to write Jasmine tests for exceptions...