meteor add mike:mocha
This meteor package allows you to easily and safely run mocha tests within Meteor. It is built upon the Velocity testing framework.
Here's an example using CoffeeScript (or check out the full Meteor project w/ tests)
MochaWeb?.testOnly ->
describe "Leaderboard", ->
describe "givePoints", ->
it "gives 5 points to the user", ->
#create a player
playerId = Players.insert {name: "TestUser1", score: 5}
Session.set "selectedPlayer", playerId
# wait 100ms for button to appear, then continue
setTimeout (->
$('button.inc').click()
player = Players.findOne(playerId)
chai.assert.equal player.score, 10
Players.remove playerId
done()
), 100
The above test will work with the leaderboard
example shipped with Meteor 1.0.
- Create the app with
meteor create --example leaderboard
- Change the current working directory to
leaderboard
- Start the app by running
meteor
- Add CoffeeScript support with
meteor add coffeescript
- Create the directory
tests/mocha/client
- Save the above test code in a file called
tests/mocha/client/leaderboard.coffee
- Navigate to the app (http://localhost:3000/ by default) and click the Velocity icon in the upper right to see test results
You're free to write your tests in any Meteor supported extension. The chai assertion library is included within this package for your convenience.
(requires Meteor 0.9+)
- Clone this repository somewhere
git clone https://github.com/mad-eye/meteor-mocha-web
- Create a packages directory in the root of your app if it doesn't already exist
cd YOUR_APP && mkdir packages
- Create a symlink to the repository you cloned
cd YOUR_APP/packages && ln -s /PATH/TO/meteor-mocha-web mike:mocha
- Add the package to the application : meteor add mike:mocha
- Run your app
Use the commmand:
meteor --test --release velocity:[email protected]_2
The release velocity:[email protected]_2
contains a fix for running
the client integration tests.
See the README for this fork https://github.com/mad-eye/meteor-mocha-web/tree/packageTest
VELOCITY_DEBUG_MIRROR=mocha meteor