GitXplorerGitXplorer
m

meteor-template-test-helpers

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
96d1312a764f268b218a955d3cc1a02699eb7e8e

Improved .eslintrc setup

committed 9 years ago
Unverified
4f7b18cb8045cb92ea0c7b126216eaf53556af07

Update README.md

mmarcodejongh committed 9 years ago
Unverified
a3658826dc01c90f051f461768d485984b43fa61

Update README.md

mmarcodejongh committed 9 years ago
Unverified
214349c6f541cf0b99619725aca33a25b13a1ab7

Update README.md

mmarcodejongh committed 9 years ago
Unverified
6bfc5ea99692452e29f7ff98377019a89a3a59e8

Update README.md

mmarcodejongh committed 9 years ago
Unverified
d3b07e7361d8619f1f689e2504e5d69a2e22f439

Added latest .versions file

committed 9 years ago

README

The README file for this repository.

Template-test-helpers

Template helpers and callbacks can easily be unit tested. The only problem is to get to them you have to rely on private properties. For example to test a onRendered callbacks you'd have to use:

let templateInstance = sinon.createStubInstance(Blaze.TemplateInstance);
templateInstance.$ = sinon.spy($);

Template[templateName]._callbacks.onRendered.call(templateInstance);

//Insert assertions here

To prevent boilerplate and having to search replace your whole project when MDG changes _callbacks to __callbacks. This package was made, when using this package instead you can write:

let templateInstance = TemplateTestHelpers.getMockTemplateInstance();
TemplateTestHelpers.getTemplateOnRenderedFunction(templateName).call(templateInstance);

//Insert assertions here

Installing

Atmosphere

Usually you'd put this package in the api.use of the onTest clause of a package you want to test.

Example:

  api.use([
    'ecmascript',
    'mike:mocha-package@0.5.8',
    'practicalmeteor:sinon',
    'practicalmeteor:chai',
    'underscore',
    'mdj:template-test-helpers@0.2.0',
    'packageYourTesting' //Make sure template-test-helpers is loaded before the package containing the template you want to test
  ]);

Important note: to be able to catch the raw event handlers, this package contains a override of Template.prototype.events. So to ensure this package works like intended make sure you specify this package BEFORE the package containing the templates you want to test.

TODO: I will write more documentation soon. For now just check the code in the client directory.