Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a fairly nice tutorial for testing with Mocha and Phantom.JS <a href="http://net.tutsplus.com/tutorials/javascript-ajax/testing-javascript-with-phantomjs/" rel="nofollow noreferrer">here</a>.</p> <p>The section on Mocha and PhantomJS is short, but the basic idea is to put DOM assertions and interactions into your Mocha test suite, run it a la client-side via a testrunner.html file, and then point mocha-phantomjs at the testrunner.html file.</p> <p>To paraphrase, your Mocha test might look like this:</p> <pre><code>describe("DOM Test", function () { var el = document.createElement("div"); el.id = "myDiv"; el.innerHTML = "Hello World!"; document.body.appendChild(el); var myEl = document.getElementById('myDiv'); it("has the right text", function () { (myEl.innerHTML).should.equal("Hello World!"); }); }); </code></pre> <p>And the testrunner.html file would be the normal setup:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt; Tests &lt;/title&gt; &lt;link rel="stylesheet" href="./node_modules/mocha/mocha.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="mocha"&gt;&lt;/div&gt; &lt;script src="./node_modules/mocha/mocha.js"&gt;&lt;/script&gt; &lt;script src="./node_modules/chai/chai.js"&gt;&lt;/script&gt; &lt;script&gt; mocha.ui('bdd'); mocha.reporter('html'); var should = chai.should(); &lt;/script&gt; &lt;script src="test/test.js"&gt;&lt;/script&gt; &lt;script&gt; if (window.mochaPhantomJS) { mochaPhantomJS.run(); } else { mocha.run(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If you'd prefer a solution run entirely from the node.js ecosystem, it's worth considering <a href="http://zombie.labnotes.org/" rel="nofollow noreferrer">Zombie.JS</a>. This Stack Overflow <a href="https://stackoverflow.com/questions/9350232/mocha-and-zombiejs">question</a> provides a basic example. </p> <p>The tradeoff is that while Zombie.JS can be used simply by requiring the node module, and is extremely fast, it's not a "real" web browser. PhantomJS is closer, as its based on webkit. Also, the first approach with mocha-phantomjs would allow you to run the client-side Mocha tests in different browsers of your choice, PhantomJS being just one of them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload