angular and dynamic templates in unit tests

2 posts, 0 answers
  1. Wray
    Wray avatar
    7 posts
    Member since:
    Aug 2013

    Posted 29 Mar Link to this post

    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.

  2. Dimo
    Dimo avatar
    8319 posts

    Posted 01 Apr Link to this post

    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.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top