Test helper to count JS-Signal dispatches. For use in unit tests.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
lib
spec
src
.gitignore
README.markdown
SpecRunner.html
js-signals-logger.sln

README.markdown

Warning

It is recomended to use jasmine-signals.

js-signal-logger is obsolete, but I left it here in case you're not using Jasmine and need some tool to simplify js-signals testing.

js-signal-logger

SignalLogger reduces the amount of repetitive code you have to write to unit test components using JS-Signals.

It counts how many times specified signals have been dispatched.

Filtering allows checking if correct parameters have been passed for signal dispatch.

API / Features

Configuration

Pass an object specifying the name and the signal.

Name is used to create SignalInfo object for each signal and attach it to the logger as new fields.

var logger = new SignalLogger({ finished: obj.finished });

SignalInfo.count

Returns the amount of times the watched signal has been dispatched.

logger.finished.count

SignalInfo.setFilter

Only count signals that match condition.

logger.finished.setFilter(function (param1, param2, ...) {
	return true; // always count this signal (default)
} );

SignalInfo.matchValues

Count signals only if dispatched with given values. It's a shortcut to setFilter.

logger.finished.matchValues(expectedInfo);

which is equivalent to:

logger.finished.setFilter(function (info) {
	return info == expectedInfo;
} );

Usage

Check the spec folder for RequireJS configuration.

Basic usage

it('should count signals', function () {
	var obj = {	finished: new signals.Signal() };
	var logger = new SignalLogger({ finished: obj.finished });

	obj.finished.dispatch();

	expect(logger.finished.count).toBe(1);
});

Filtering

Method passed to setFilter should return false if signal should be ignored.

it('should count filtered signals', function () {
	var obj = {	finished: new signals.Signal() };
	var logger = new SignalLogger({ finished: obj.finished });
	logger.finished.setFilter(function (dispatchArgs) {
		return dispatchArgs === 1; // only count signals dispatched with 1
	});

	obj.finished.dispatch(1);
	obj.finished.dispatch(5);
	obj.finished.dispatch(1);

	expect(logger.finished.count).toBe(2);
});