-
-
Save abner/ee8309a3a3b9f7dddf4a to your computer and use it in GitHub Desktop.
Yeoman - AngularJS : karma configuration for directives testing
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
// file: app/scripts/directives/myDirective.js | |
angular.module('someApp.directive').directive('myDirective', function () { | |
return { | |
templateUrl: 'templates/myDirective.html', // HERE | |
.... | |
} | |
}); |
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
// file: karma.conf.js | |
// Karma configuration | |
// http://karma-runner.github.io/0.10/config/configuration-file.html | |
module.exports = function (config) { | |
config.set({ | |
basePath: '', | |
frameworks: ['jasmine'], | |
files: [ | |
'app/bower_components/angular/angular.js', | |
'app/bower_components/angular-mocks/angular-mocks.js', | |
'app/scripts/*.coffee', | |
'app/scripts/**/*.coffee', | |
'test/mock/**/*.coffee', | |
'test/spec/**/*.coffee', | |
'app/templates/**/*.html' // HERE | |
], | |
preprocessors: { | |
'**/*.coffee': 'coffee', | |
'app/templates/**/*.html': 'ng-html2js' // HERE | |
}, | |
ngHtml2JsPreprocessor: { | |
// strip this from the file path | |
stripPrefix: 'app/' // HERE | |
}, | |
autoWatch: true, | |
... | |
}); | |
}; |
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
// file: test/spec/directives/myDirective.js | |
describe('Directive: myDirective', function() { | |
var element, scope; | |
beforeEach(module('someApp.directive')); | |
beforeEach(module('templates/myDirective.html', 'templates/myDirective.html')); // HERE. load module prepared by ng-html2js | |
beforeEach(inject(function($compile, $rootScope) { | |
scope = $rootScope.$new(); | |
// prepare scope in which your directive should be used | |
// ... | |
element = angular.element('<myDirective></myDirective>'); | |
$compile(element)(scope); | |
scope = element.scope(); | |
return scope.$apply(); | |
})); | |
it('fancy-dancy test', inject(function($compile) { | |
expect(element.text()).toBe('...'); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment