Last active
January 17, 2016 16:52
-
-
Save nkijak/42dd8ef58aee4bf80bf8 to your computer and use it in GitHub Desktop.
Angular Directive template unit testings
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
module.directive("speechBubble", [function() { | |
function link(scope, element, attrs) { | |
function updateText(values) { | |
var text; | |
try { | |
text = "Drop and Give Me "+values.reduce(function(acc, i) { return acc + i;}, 0) + "!"; | |
} catch (e) { | |
text = "Beat your face!"; | |
} | |
element.find("div.speech").text(text); | |
} | |
scope.$watch('workout', function(values, oldValues){ | |
updateText(values); | |
}); | |
updateText(); | |
} | |
return { | |
restrict: 'E', | |
templateUrl: '/templates/speechBubble.html', | |
link: link, | |
scope: { | |
workout: "=" | |
} | |
} | |
}]); |
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
describe('directives', function() { | |
beforeEach(angular.mock.module('dgmt.ui.elements')); | |
var rootScope; | |
var element; | |
describe('speech-bubble', function(){ | |
beforeEach(angular.mock.module('/templates/speechBubble.html')); | |
beforeEach(inject(function($compile, $rootScope) { | |
rootScope = $rootScope; | |
element = $compile("<speech-bubble workout='workout'/>")($rootScope); | |
$rootScope.$digest(); | |
})); | |
it('should display default message without workout', function() { | |
expect(element.html()).toContain("Beat your face!"); | |
}); | |
it('should display a total count message', function() { | |
rootScope.workout = [1,1,1,1]; | |
rootScope.$digest(); | |
expect(element.html()).toContain("Drop and Give Me 4!"); | |
}); | |
}); | |
... |
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
module.exports = function(config) { | |
config.set({ | |
basePath: '../', | |
files : [ | |
'lib/jquery.js', | |
'lib/angular.js', | |
'lib/angular-*.js', | |
'app/scripts/**/*.js', | |
'test/unit/**/*.js', | |
'app/templates/*.html' | |
], | |
exclude: [ | |
'lib/angular-loader.js', | |
'lib/angular-scenario.js', | |
], | |
ngHtml2JsPreprocessor: { | |
stripPrefix: 'app' | |
}, | |
frameworks: ['jasmine'], | |
browsers: ['PhantomJS'], | |
reporters: ['spec'], | |
preprocessors: { | |
'app/templates/*.html': 'ng-html2js' | |
}, | |
colors: true | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment