Testing Directives
Why Stack Overflow recommends it
Stack Overflow users link it when asking or answering how to unit test AngularJS directives and set up Jasmine and Testacular tests.
Recommended by 1 people across 1 different months, 2013 to 2014.
What it is
A 2012 conference-style talk from the official Angular channel in which Vojta Jina of the AngularJS team at Google explains how to unit test AngularJS directives. He covers techniques for compiling and exercising directives in tests and for keeping the suite fast using the Testacular test runner, which he authored.
What people said
Recommends user2740086 · 2014-06 · Stack Overflow · on “Testing a controller in Angular with several dependencies”
Where to Provide Dependencies You should provide all of your dependencies in your first beforeEach statement. I mock/fake mine with SinonJs [LINK] . This helps you take advantage of angular's dependency injection to isolate each piece of your application. You should never call a dependency and expect an actual instance of it to return data in a unit test, as that would increase the coupling of your code and make it far more brittle. Mocking Resource Calls For resource calls, I simply create a fake resource object with promises and whatnot included. You can then resolve or reject those promises and provide fake data to test your controller logic. In the plunk below, I've essentially mocked ou
Cites user1703761 · 2013-02 · Stack Overflow · on “How do I test HTML that has to be rendered with testacular and jasmine”
I want to test if a directive binds the correct jquery functions to the DOM and that they work. For instance i want to test if an element is visible after it was slid up with $.slideUp() or i want to execute a click event on an html input. It seems that i need to somehow attach the compiled directive to the DOM to make this happen. I've watched the testing directives video on youtube [this video] where he says that it is possible but he doesnt mention how you do it. I'm kinda stuck. Heres the link to the failing test: [LINK]
Cites Apples · 2013-04 · Stack Overflow · on “AngularJS directive testing”
I am trying to test the following directive. angular.module('myModule.directives', []) .directive('test', function() { return { restrictions: 'E', scope: {}, transclude: true, replace: true, template: '<div><ui><li>a</li></ul></div>' } }); In my test: describe('directives', function () { var compile, scope, test; beforeEach(module('myModule.directives')); beforeEach(inject(function ($compile, $rootScope) { compile = $compile; scope = $rootScope; test = angular.element('<test></test>'); compile(test)(scope); scope.$digest(); it('should render the test directive', function () { var lis = test.find('li'); console.log(lis.length); // should output 1 }); })); Test fails and outputs 0. I am curiou