I am using angular-translate in my custom directive template, for example:
<!-- directive template -->
<button>{{"ers.diagramComponent.resizeOriginalButton" | translate}</button>
My json that maps to this translate value:
{
"ers.diagramComponent.resizeOriginalButton": "Original"
}
I was originally getting this error:
Error: [$injector:unpr] Unknown provider: translateFilterProvider <- translateFilter
I corrected that by adding:
<!-- This is at the top level, runs before all tests -->
describe("Directive", function () {
beforeEach(angular.mock.module("directive"));
var mockFilter = function (value: any) {
return value;
};
beforeEach(function () {
angular.mock.module(function ($provide:any) {
$provide.value("translateFilter", mockFilter);
});
});
});
Found the above here: How to mock angular translate filter in unit tests for directives
I am trying to now get that translate value to match in my karma/jasmine tests. My failing test looks something like this:
var actualSizeHtml = diagramDirective.find("button").html();
expect(actualSizeHtml).toEqual("Original");
My failing test:
Expected 'ers.diagramComponent.resizeOriginalButton' to equal 'Original'.
So basically I can't figure out how to translate "ers.diagramComponent.resizeOriginalButton" so that it equals "Original", which is what the test is looking for.
Here is my config for setting up the $translateProvider in the components, the resources folder holds the json for my key/value pairs:
angular.module("app",["pascalprecht.translate"]).config(["tmhDynamicLocaleProvider", function(tmhDynamicLocaleProvider) {
$translateProvider.useStaticFilesLoader({
prefix: "resources/locale-",
suffix: ".json"
});
$translateProvider.preferredLanguage("en-us");
$translateProvider.useSanitizeValueStrategy("escape");
}]);
But that configuration has nothing to do with my tests.