title: PhantomJS pass argument to evaluate
body: <p>I have a small test app using NightmareJS as a wrapper for PhantomJS I want to test for the existence of a class on an element. I have this code:</p>
  
  <pre><code>new Nightmare()
    .goto(baseURL)
    .evaluate(function() {
      return document.querySelector('body');
    }, function(element) {
      element.className.should.equal(expected)
      callback();
    })
    .run();
  </code></pre>
  
  <p>How can I pass an argument to the querySelector method rather than hardcoding the tag?</p>
  
  <p>I have tried</p>
  
  <pre><code>var tag = body;
  new Nightmare()
        .goto(baseURL)
        .evaluate(function() {
          return document.querySelector(tag);
        }, function(element) {
          element.className.should.equal(expected)
          callback();
        })
        .run();
  </code></pre>
  
  <p>However PhantomJS always returns an error that it cannot find the variable.</p>
  
  <p>How can I accomplish passing a variable argument to the querySelector method?</p>