xen
xen

Reputation: 645

Is meteor code effectively unit testable?

I am currently looking into the meteor framework and this question immediately jumps to mind. Is code which I write (for example Template.xxx code or Template.xxx.events) actually testable in any way?

Of course you can test code which is not bound to the meteor runtime as you would any other code, but my impression is that most code you will write inside of meteor is somehow scoped to meteor and its functions.

Upvotes: 14

Views: 808

Answers (5)

Benjamin Crouzier
Benjamin Crouzier

Reputation: 41865

Velocity has been selected as the official testing framework for meteor 1.0. The announcement has been made in the last meteor devshop (june 2014).

Packages developed with velocity:

Upvotes: 1

Dan Dascalescu
Dan Dascalescu

Reputation: 151988

As of February 2014, Meteor code is unit-testable using the built-in Tinytest framework, as long as you move all your application code into packages, which you should do anyway. The quick-and-dirty way amounts to adding a package.js file. That file serves to:

  1. Declare your exports. It's good practice for clean namespacing to have one global object for your app
  2. Declare your test files

Here is an example by Eventedmind - https://github.com/EventedMind/meteor-file

You can see in meteor-file-test.js that it accesses MeteorFile, which is declared as an export in package.js.

Upvotes: 5

dmayo3
dmayo3

Reputation: 73

There doesn't seem to be any official test framework yet apart from the undocumented Tinytest (see the video tutorial) and its helpers, but you can always stub/mock out the Meteor framework API like I've done in this trivial example on github.

I imagine it could get a lot harder for non-trivial applications, so it's probably a good idea to separate core application logic away from Meteor API calls.

Upvotes: 6

Xolv.io
Xolv.io

Reputation: 2533

I've created a blog post here showing how to do effective unit testing in Meteor, along with an example project on GitHub. Hope it helps.

http://blog.xolv.io/2013/04/unit-testing-with-meteor.html

Upvotes: 1

Jabbslad
Jabbslad

Reputation: 546

I think it is testable although I haven't looked into it too deeply.

If you open up the liveui package ($METEOR_HOME/packages/liveui) there seems to be quite a few unit tests written using TinyTest and testing the rendering. I think that would be a good place to start:-

  • liveui_tests.js
  • liveui_tests.html

etc.

Hope that helps

Upvotes: 1

Related Questions