We use Jest
for our unit testing needs. To run Jest in watch mode locally so the tests run automatically while you're developing run:
yarn run test
Before running the tests this will set up a RethinkDB database locally called "testing"
. It will run the migrations over it and then insert some dummy data. This is important because we test our GraphQL API against the real database, we don't mock anything, to make sure everything is working 100%.
When you exit the testing process with CTRL+C
it will clean the database from all its data. It leaves the migrations in tact though, since there's no reason we should have to run them everytime we run the test suite.
In edge cases it could happen that you end up with bad data locally and that tests fail/pass even though they shouldn't. To get rid of the stale data just stop the testing process and optionally run yarn run posttest
to make extra sure there's nothing in the database anymore, before restarting the testing process to start from a clean slate.