I have written several unit tests recenlty and I wonder if there is a way to make html string (binding template) that appeals to directive (or component) from javascript function. Here is an example.
I have some directive and I'm testing it like this
function test($rootScope, $compile) {
var scope = $rootScope.$new();
var elem = $compile(angular.element(
'<app-foo-bar attr1="val1" attr2="val2"></app-foo-bar>'
))(scope);
scope.$apply();
}
Declaring an element string seems to be a little awkward especially if there is a dozen of attributes. It would be very handul for unit-testing if there is a function that generates html string from object like this.
genHtmlString('fooBar', {
attr1: 'val1',
attr2: 'val2'
});
And output would be of course
<app-foo-bar attr1="val1" attr2="val2"></app-foo-bar>
It seems like a common problem to me, but I can't find any angular, karma or jasmine functionality that would be helpful in writing such a function.