jsf-mock
v0.1.2
Published
Mock implementation for jsf.js
Downloads
5
Readme
jsf.mock.js
When it comes to TDD, jsf.js
needs to be mocked somehow.
Quickstart
Just include jsf.mock.js
and you are good to go.
Mocked methods:
jsf.ajax.addOnEvent
adds the given function as a normal event handler to a local arrayjsf.ajax.addOnError
adds the given function as an error handler to the local array
Helper methods:
jsf.ajax.fire([type], eventData, [name])
fires an event with the given data. If notype
is provided, only the non error handlers will be used. Iftype === 'error'
only the error handlers will be used. Finally if aname
is provided handlers will be filtered based on their name.jsf.ajax.hadlersSize([query])
returns the size of the available non error handlers if noquery
is given. Iferror
is given as a query then returns the number of the error handlers. In any other case it returns the handlers with aname
equal to the given query.jsf.ajax.clearHandlers([query])
clears all the existing non error handlers available. Ifquery === error
it clears the error handlers. In any other case it clears the handlers with aname
equal to the given query.
Here is an exaple of how to use it
var errorHandler = function () {};
jsf.ajax.addOnEvent(function () {});
jsf.ajax.addOnError(errorHandler);
jsf.ajax.addOnError(function anotherErrorHandler() {});
jsf.ajax.fire({}); //only the anonymous handler will be used
jsf.ajax.fire('error', {}); //only the error handlers will be used
jsf.ajax.fire('error', {}, 'anotherErrorHandler'); // only the anotherErrorHandler will be used
Developing
Assuming that you have node installed, you can gulp tdd
in order to watch for file changes and run the tests. Before you commit make sure you run the default gulp
task.
Finally you can use gulp to to a release with gulp release [--major|minor]
. If no major or minor will be given the version will get bumped as a patch.
References
- The jsf.js api