Friday 15 February 2013

angularjs - How to test directives that use templateUrl and controllers? -


EDIT: After asking the question, I am now editing it to expand my findings.

My app has been modular using instructions. I am writing my instructions that they (1) use the template URL of their own area (2), and (3) get maximum logic and server data in their controller

< / P>

An examination is written for each instruction as the instruction Uses template url, so I used html2js The Html key should be included as a module - which Emplet puts in cache.

Then, I compiled the instruction, and started the link function with rootScope. I had a problem in getting the template HTML - the data resolved using $ Digest was resolved through comprehension issues, understanding. Document it all below.

Director:

  Angular. Module ('myApp'). Instructions ('product column', function () {return (limited: 'AE', scope: true, template url: 'partial / instructions / product-thumb_ html', // Controller controls most of the tasks: Product Stuff Controller}} ); Describe ("Unit: Testing Directives", function () {var elm, scope, linkFn; first (module ('ogApp', 'partial / directions / product-thumb_ html') // puts- thumb.html (In template cache) first (inject (function ($ Rootscope, $ compilation) {ALM = angular element ('product-thumbs & gt; & lt; / product-thumb & gt;'); scope = $ Rootscope; link Fn = $ compile elm; scope. $ Digest (); // needs to be digested to bring HTML from template to cache console.log ('post compile', elm.html ()); // & Lt; == h Tml is still {{}}};) ('should show one thumbs', function () (injection (function ($ controller) {linkFn (scope); // will create a new radius (since our director Creates a new scope), runs the controller with it, and binds that element to a new radius. $ Digest (); console.log ('Post link', LLMM); // & lt ; == HTML / byte test data (controller ADP sets $ on handler for ProductData event) Scope. $ P Rsarn ( 'Adprodktdeta ", {title:" Tests deputy named "Product ID:" 123 ", the main Imag EUrl:" TEST.JPG "}); Scope $ digest (). Expected (elm.fund ('h5'). Text ()). To.equal ("test display name"); // & lt; === success}); });    

No comments:

Post a Comment