Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere should unit tests be placed in Meteor?
    text
    copied!<p><strong>Is there a place where my tests can live without being run by Meteor?</strong></p> <p>I just started my first Meteor project, and began by writing unit tests with <a href="http://visionmedia.github.com/mocha/" rel="nofollow noreferrer">Mocha</a> and <a href="https://github.com/visionmedia/should.js#readme" rel="nofollow noreferrer">should.js</a>. Though mocha runs without a problem, the tests prevent Meteor from starting up since it has issues using node's <code>require</code> instead of <code>__meteor_bootstrap__.require</code> (<a href="https://gist.github.com/3240588" rel="nofollow noreferrer">full error message</a>).</p> <p>That being said, <em>Meteor should not be running my tests!</em> According to the <a href="http://docs.meteor.com/#structuringyourapp" rel="nofollow noreferrer">Meteor documentation</a>, code can only be placed on the client, server, or both. Unit test suites do no belong in these categories, and I am <a href="https://stackoverflow.com/questions/10128768/how-does-one-do-testing-in-meteor-is-there-an-easy-way-to-plug-in-jasmine-or-mo">not the only person</a> confused by Meteor's lack of a well-defined location for placing automated tests.</p> <p>Right now, my tests are kept in <code>server/test/</code>, with the contents of each file wrapped in the block:</p> <pre><code>if (typeof(Meteor) === 'undefined') { ... } </code></pre> <p>While this works, it does not feel elegant. Do you have any other suggestions for structuring your tests with your Meteor app?</p> <p><strong>Update:</strong> in lieu of explicit instructions in the Meteor docs, I followed the <a href="http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application" rel="nofollow noreferrer">Rails folder conventions</a> (4th paragraph), using a folder called <code>test</code> for storing my testing assets. I later moved this to <code>server/test</code> since I did not want it loaded on the client.</p>
 

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