angularjs - Jasmine Test - Unknown provider $sceProvider -
i trying write jasmine test filter. here 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 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 <br />', function () { expect($sce.gettrustedhtml(texttohtmlsafefilter('testing\n'))).toequal('testing<br />'); }); });
i receiving error in karma when running test:
error: unknown provider: $sceprovider <- $sce
can tell me i'm doing wrong?
obviously module doesn't work fine. have create module empty dependency list!
var app = angular.module('cpscore.filters', []);
Comments
Post a Comment