Book Image

Meteor Design Patterns

By : Marcelo Reyna
Book Image

Meteor Design Patterns

By: Marcelo Reyna

Overview of this book

Table of Contents (13 chapters)

Unit tests


Unit tests are much easier to build than behavior tests. These tests make sure that only a section of the web application is working correctly, such as Meteor.method or a template helper.

Unit tests make it quicker to find bugs in broken behavior tests. They should be used mostly in parts that you know can break easily, such as a publisher or a particular helper.

To run unit tests, we are going to use the sanjo:jasmine package:

meteor add sanjo:jasmine

Now create two directories: /jasmine/client/integration and /jasmine/server/integration. These are the special directories where jasmine runs tests. Let's build a quick test for the products publisher:

# /tests/jasmine/client/integration/publishers/products_pub_test.coffee

do ->
  'use strict'

  describe "Products publisher", ->
    it "should return product data", ->
      # SETUP
      subscription = Meteor.subscribe("products")

      if subscription.ready()
        # EXECUTE
        product = Products.findOne()

  ...