Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AngularJS - Test simple directive
<!DOCTYPE html>
<!-- // source http://jsbin.com/gazax/1 -->
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/42401/jasmine-html_1.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/42401/boot.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-mocks.js"></script>
<link type="text/css" rel="stylesheet" href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/42401/jasmine_1.css"></link>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var app = angular.module('myApp', []);
app.directive('ehSimple', function() {
return function(scope, element) {
element.addClass('plain');
};
});
describe('Directive tests', function() {
var $scope;
var element;
beforeEach(module('myApp'));
beforeEach(inject(function($compile, $rootScope) {
$scope = $rootScope;
element = angular.element("<div eh-simple></div>");
$compile(element)($rootScope);
}));
it('should add a class "plain"', function() {
expect(element.hasClass("plain")).toBe(true);
});
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">var app = angular.module('myApp', []);
app.directive('ehSimple', function() {
return function(scope, element) {
element.addClass('plain');
};
});
describe('Directive tests', function() {
var $scope;
var element;
beforeEach(module('myApp'));
beforeEach(inject(function($compile, $rootScope) {
$scope = $rootScope;
element = angular.element("<div eh-simple></div>");
$compile(element)($rootScope);
}));
it('should add a class "plain"', function() {
expect(element.hasClass("plain")).toBe(true);
});
});</script></body>
</html>
var app = angular.module('myApp', []);
app.directive('ehSimple', function() {
return function(scope, element) {
element.addClass('plain');
};
});
describe('Directive tests', function() {
var $scope;
var element;
beforeEach(module('myApp'));
beforeEach(inject(function($compile, $rootScope) {
$scope = $rootScope;
element = angular.element("<div eh-simple></div>");
$compile(element)($rootScope);
}));
it('should add a class "plain"', function() {
expect(element.hasClass("plain")).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment