Eusebiu Schipor Let’s talk tech!

  • To test our directive, we’ll need to create a variable that hold our expected directive output.
  • In the test method we need to place an item object on the $rootScope, with the property name that is passed in our directive.
  • Your email was added to our subscribers list!
  • Directives are reusable components that get used throughout our application and testing their functionality is definitely important.
  • beforeEach(inject(function($templateCache) { var template = null; var req = new XMLHttpRequest(); req.onload = function() { template = this.responseText; }; req.open(‘get’, ‘my-template.html’, false); req.send(); $templateCache.put(‘my-template.html’, template); }));


Directives are reusable components that get used throughout our application and therefore, testing their functionality is definitely important. To test our directive, we’ll need to
create a variable that hold our expected directive output. In the test method we need to place an item object on the $rootScope, with the property name that is passed in our directive.


@eusebiuschipor: Testing AngularJS 1.x directives: #angularjs #javascript #frontend

Posted on January 23, 2017

Directives are reusable components that get used throughout our application and therefore, testing their functionality is definitely important. To test our directive, we’ll need to create a variable that hold our expected directive output. In the test method we need to place an item object on the $rootScope, with the property name that is passed in our directive.

var $compile, $rootScope, expectedHtml = ‘my html’; beforeEach(module(‘MyApp’)); beforeEach(inject(function(_$rootScope_, $_compile_) { $rootScope = _$rootScope_; $compile = _$compile_; }));

beforeEach setup for using templateUrl:

Eusebiu Schipor Let’s talk tech!