Skip to content

Instantly share code, notes, and snippets.

@murindwaz
Last active December 22, 2015 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murindwaz/8fe4658ca3d3d0de1108 to your computer and use it in GitHub Desktop.
Save murindwaz/8fe4658ca3d3d0de1108 to your computer and use it in GitHub Desktop.
Testing AngularJS directive controllers with Jasmine and Karma
/**
* @link http://daginge.com/technology/2014/03/03/testing-angular-directive-controllers-with-jasmine-and-karma/
*http://stackoverflow.com/a/25191546/132610
http://stackoverflow.com/a/26404453/132610
http://derpturkey.com/unit-testing-directives-in-angular/
*/
describe("Directive", function () {
var $scope;
beforeEach(inject(function($rootScope, $compile) {
$scope = $rootScope.$new();
var element = angular.element("<test></test>");
template = $compile(element)($scope);
$scope.$digest();
controller = element.controller;
}));
it("should toogle open when toggle() is called", inject(function() {
$scope.open = false;
$scope.toggle();
expect($scope.open).toBeTruthy();
$scope.toggle();
expect($scope.open).toBeFalsy();
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment