I am trying to write a jasmine test for my filter. Here is my filter:
angular.module('CPSCore.Filters').filter('TextToHtmlSafe', ['$sce', function ($sce)
{
return function (text)
{
if (!text)
return text;
var htmlText = text.replace(/\<br \/\>/g, '\n');
htmlText = htmlText.replace(/\<br\/\>/g, '\n');
htmlText = htmlText.replace(/\<br\>/g, '\n');
htmlText = htmlText.replace(/\</g, '< ');
htmlText = htmlText.replace(/\&/g, '& ');
htmlText = htmlText.replace(/\n/g, '<br />');
return $sce.trustAsHtml(htmlText);
};
}]);
here is my jasmine test:
describe('CPSCore.Filters', function() {
var TextToHtmlSafeFilter, $sce;
beforeEach(module('CPSCore.Filters'));
beforeEach(inject(function (_$sce_, $filter) {
$sce = _$sce_;
TextToHtmlSafeFilter = $filter('TextToHtmlSafe');
}));
it('should replace \n with <br />', function () {
expect($sce.getTrustedHtml(TextToHtmlSafeFilter('testing\n'))).toEqual('testing<br />');
});
});
I am receiving this error in Karma when running the test:
Error: Unknown provider: $sceProvider <- $sce
can anyone tell me what I'm doing wrong?
Aucun commentaire:
Enregistrer un commentaire