1
votes

I'm writing a meteor package and are writing some unit tests on it. The package contains some templates, so I'd like to test the templates as well. The template has an onRendered hook. In my unit test, I call function Blaze.renderWithData to render the template that I want to test. I expect the onRendered hook is called by this function. However, it doesn't.

I use jasmine to do unit test. The test code is as below:

for i in [0...tests.length]
  oneGroupTests = tests[i]
  describe  oneGroupTests.name, ->
    for i in [0...oneGroupTests.tests.length]
      test = oneGroupTests.tests[i]
      do (test) ->
        it test.name, ->
          expect(test.template).toBeDefined()
          expect(test.test).toBeDefined()
          div = document.createElement("div")
          Blaze.renderWithData(Template[test.template], test.data, div)
          if test.before
            test.before($(div))
          test.test($(div))
          $(div).remove()

Any idea how to invoke the onRendered hook programmatically?

Thanks.

1

1 Answers

0
votes

Try calling Tracker.flush() prior to testing if your onRendered routine fired. Look here for more details:

http://docs.meteor.com/#/full/tracker_flush

The reason you're having this problem is probably that the callbacks are not fired immediately but only in the next "computation" cycle.

http://docs.meteor.com/#/full/tracker_computation

Calling Tracker.flush() will force Meteor to recompute all pending computations.