O'Reilly logo

AngularJS Testing Cookbook by Simon Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a test spec

Using the global Jasmine function called it, we can define our spec that includes the title and a function containing the spec code. When unit testing, as opposed to end-to-end testing, I follow the rule of one expectation per spec. This rule focuses the spec onto one area of functionality and helps clarify what is either successfully working as expected or on the other hand, failing. The drawback of this approach is that it involves writing more code. This recipe will provide you with an example spec for a directive, demonstrating how to update the scope and then assert a value within the DOM element.

Getting ready

For this example, I will test against a directive that updates the element text content based on a scope value. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required