This is a migrated thread and some comments may be shown as answers.

angular and dynamic templates in unit tests

1 Answer 145 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Wray
Top achievements
Rank 1
Wray asked on 29 Mar 2016, 12:45 PM

We have a treeview that uses a template. The template is inline with the HTML for the page and is referred to with a JQuery id search. This is what is shown for the template demo for Kendo.

However this is incompatible with unit testing an angular controller containing options including the reference to the template in HTML which is not loaded in a controller test. Result is that unit tests blow up trying to reference the template with JQuery.

Now the angular demo does this in a way that should be compatible in that it embeds a <span> with a k-template with bound items from the controller, so the controller can be isolated for unit test.

However our template is dynamic in that it is a conditional template similar to # if (mybool) #  some html  #else# some other html. (you get the idea).

There appears to be no examples of how to do this type of dynamic template that would be compatible with an angular unit test, because this type of template is not HTML it is actually a script.

Before we redo the app, has anyone got an example? The only other solution we have thought of is to change the template string to a function and call a service that dynamically compiles a string, but we are not sure if this would be worth the effort (would work)... even though it would allow mocking the service to isolate the controller.

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 01 Apr 2016, 07:46 AM
Hello Wray,

The Kendo UI template syntax has been designed to be compatible with the Kendo UI templating engine, which ultimately generates an HTML string to be rendered on the page, and is able to work with script expressions. I am afraid we are not able to comment on the integration question that you have posted, but I will leave the thread open for somebody else who has researched a similar scenario to share an opinion.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Wray
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or