So far, that’s all and well, as long as I only want to make assertions about the rendered HTML. But let’s say I want to test a method I attached to the Template instance (in the onCreated callback).
How can I get a hold of the Template instance from within the withRenderedTemplate callback?
I’ve been reading the docs for over an hour and tried different things, but I can’t get a hold of the instance. According to the docs, Blaze.renderWithData() returns a Blaze.View, which is supposed
to have a templateInstance() method. However, in my tests, that was not the case.
Maybe I am not answering your question directly, but in the generated template, withing helpers you can use Template.instance() to get the current template instance. In onRendered, onCreated etc. you simply call this.
For the data that you passed in your BlazeRenderWithData, you access it from the data variable (this.data.field).
I don’t think you really want to access the template instance from your external code, as that would defeat the purpose. Data flows into the template – out flows go to the DB or to methods.