lundi 2 mars 2015

Mocking Angular bootstrap-ui directive for unit tests

I'm trying to write a unit test to ensure that a directive works correctly.


The directive's template includes the Angular bootstrap datepicker, so I would like to be able to mock that.


This question says I should be able to mock directives by creating new directives with the same name using $compileProvider and setting a high priority and terminal to true:



beforeEach(function() {
inject([
'$compileProvider',
function($compileProvider) {
$compileProvider.directive('datePickerOptions', {
priority: 100,
terminal: true,
template: ''
});

$compileProvider.directive('datePickerPopup', {
priority: 100,
template: ''
});
}]);
});


It also says that you can mock directives by just overriding their factory functions like so:



beforeEach(module(function($provide) {
$provide.factory('datePickerOptionsDirective', function() {
return {};
});
$provide.factory('datePickerPopupDirective', function() {
return {};
});
}));


Neither of these methods are working for me. I'm using Karma unit tests. Any thoughts?


Aucun commentaire:

Enregistrer un commentaire