title: Proper method for integration testing with sanjo:jasmine and Blaze.render in
body: <p>I am using <code>sanjo:jasmine</code> to do testing of my app.  I am trying to do a simple check to see if a link element is present in my header template using a client-side integration test and <code>Blaze.render</code>.  I am using <code>alanning:roles</code> for managing the roles.</p>
  
  <p>In my template I something like this (minimized for simplicity sake):</p>
  
  <pre><code>&lt;template name="header"&gt;
      &lt;!-- Fixed navbar --&gt;
      &lt;div class="navbar navbar-default navbar-top navbar-fixed-top" role="navigation"&gt;
          &lt;div class="container"&gt;
              &lt;div class="navbar-header"&gt;
                  &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                      &lt;span class="sr-only fa fa-bars"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;/button&gt;
                  &lt;a id="homelink" class="navbar-brand {{isActiveRoute regex='home' className='active'}}" href="/"&gt;AppName&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="navbar-collapse collapse"&gt;
                  &lt;ul class="nav navbar-nav"&gt;
                      &lt;li class="{{isActiveRoute regex='dashboard' className='active'}}"&gt;&lt;a id="daskboardlink" href="{{pathFor 'dashboard'}}"&gt;Dashboard&lt;/a&gt;&lt;/li&gt;
                      {{#if isInRole 'ADMIN'}}
                          &lt;li class="{{isActiveRoute regex='admin' className='active'}}"&gt;&lt;a id="adminlink" href="{{pathFor 'admin'}}"&gt;Administration&lt;/a&gt;&lt;/li&gt;
                      {{/if}}
                  &lt;/ul&gt;
                  &lt;ul class="nav navbar-nav navbar-right"&gt;
                    {{#if currentUser}}
                      &lt;a href="/signout"&gt;Sign Out&lt;/a&gt;
                    {{else}}
                    &lt;a href="/signin"&gt;Sign In&lt;/a&gt;
                    {{/if}}
                  &lt;/ul&gt;
              &lt;/div&gt;
              &lt;!--/.nav-collapse --&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/template&gt;
  </code></pre>
  
  <p>And in my test I do:</p>
  
  <pre><code>describe("Header template - NO MOCKS", function() {
    it("should not show Admin for anonymous users", function() {
      var div = document.createElement("DIV");
      Blaze.render(Template.header, div);
  
      expect($(div).find("#adminlink")[0]).not.toBeDefined();
    });
  
    it("should show home for anonymous users", function() {
      var div = document.createElement("DIV");
      Blaze.render(Template.header, div);
  
      expect($(div).find("#homelink")[0]).toBeDefined();
    });
  
  
    ////////////////////////
    // Admin user header tests
    it("should be able to login an admin user", function() {
      Meteor.loginWithPassword('admin', 'admin', function (err) {
        expect(err).toBeUndefined();
        done();
      });
    });
  
    it("should show Forms for admin users", function() {
      var div = document.createElement("DIV");
      Blaze.render(Template.header, div);
  
      expect($(div).find("#adminlink")[0]).toBeDefined();
    });
  
    it("should be able to logout an admin user", function (done) {
      Meteor.logout(function (err) {
        expect(err).toBeUndefined();
        done();
      });
    });
  });
  </code></pre>
  
  <p>The first set of tests for anonymous users passes fine, as does the login and logout for the Admin.  However, the test to see if the <code>#adminlink</code> is present fails.  This seems to be the correct way to test if an element is present from within a test, but it seems like maybe the template isn't fully rendered yet.</p>