Join the DZone community and get the full member experience.Join For Free
Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.
Jasmine is made for unit testing. Unit tests are supposed to test only one component of your application. A component can be a function, an object, a module, basically everything self-contained that acts like a black box to the outside world. You usually want to avoid your unit tests failing because another component failed. That’s why you want to test your components in isolation as much as possible.
For example, you may not want to send data to another server in your unit tests or you don’t want to manipulate a page’s DOM. But you want to make sure that the components that are responsible for these tasks get called correctly. How can we do that?
Jasmine provides a feature called spies. A spy listens to method calls on your objects and can be asked if and how a method got called later on.
In this screencast, we show you how you can use spies to check if methods got called. We check if data gets sent to the server without ever performing a request by spying on jQuery’s
Up Next Testing Tuesday: Testing Asynchronous Operations
Published at DZone with permission of Clemens Helm , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.