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

Introduction


The primary objective of unit testing is to test a method, object, or component in isolation and see how it behaves in different circumstances. However, there are situations where a method/object has dependencies on other methods or objects. In this scenario, we need to design tests/specs across the units/methods or components to validate behavior or simulate a real-time scenario. However, due to non-availability of dependent methods/objects or a staging/production environment, it is quite challenging to write Jasmine tests for methods that have dependencies on other methods/objects. This is where mocks come into the picture. A mock is a fake object that replaces the original object/method and imitates the behavior of the real object, without going into the nitty-gritty of creating the real object/method.

Mocks work by implementing the proxy model. Whenever we create a mock object, it creates a proxy object, which replaces the real object/method. In our test method, we can define...