-
-
Save murindwaz/8fe4658ca3d3d0de1108 to your computer and use it in GitHub Desktop.
Testing AngularJS directive controllers with Jasmine and Karma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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