waartaa/waartaa — pull request #102 by D-Ne0 (2014-05-12 20:29:02+00:00)
Title: A simple unit test to demonstrate how to use RTD

The concept behind RTD unit testing framework is to test app code in a non-meteor context environment. This means Meteor objects, it's packages etc. are not available during testing. So, while I was testing a template function, there were alot of errors like 'undefined is not an object "Template.server_channels"'. To remove these error I tried following techniques:

1. As suggested by RTD author: Create stubs for whatever you require in unit testing. Refer to this for more details: https://github.com/xolvio/rtd/issues/87. But this was not feasible because I had to create too many stubs.

2. Then I looked at test/karma.conf.js(originally present in dir node_modules/rtd). It has a configuration variable called 'files' which allows you to load only specific app files, thus removing the pain of creating any extra stubs. You can find in this pull request that I am loading only one app file(from test/karma.conf.js) which I had tested(test/client/chat/chat_connections/channels.js) and created stubs for only that file.

Conclusion: This is the best approach I could think of to unit test Waartaa. Since alot of code has already been written in Waartaa and RTD follows TDD techinque. So I think the only way to unit test is to load only those files(by specifying it in test/karma.conf.js) which you want to unit test.

Let me know If this approach suits you.

PS: Please also look at the directory structure inside test/unit/client where the first test is placed.