Directives, as you should know, attach special behavior to a DOM element. When AngularJS compiles and returns the element on which the directive is applied, it is wrapped by either jqLite or jQuery. This exposes an API on the element, offering many useful methods to query the element and its contents. In this recipe, you will learn how to use these methods to retrieve elements using selectors.
Follow the logic to define a beforeEach()
function with the relevant logic to set up a directive as outlined in the Starting with testing directives recipe in this chapter. For this recipe, you can replicate the template that I suggested in the first recipe's There's more… section. For the purpose of this recipe, I tested against a property on scope named deejay
:
var deejay = { name: 'Shortee', style: 'turntablism' };
You can replace this with whatever code you have within the directive you're testing.