Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Commit

Permalink
_event calls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-5v committed May 9, 2013
1 parent 8bcc270 commit b8d406e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index.js
Expand Up @@ -132,17 +132,19 @@ logic.prototype = {
return function logic_exec(results) {

var execs = provs.map(function(prov, i) {
var name = names[i];
var event = that._event(names, results, params, options);
var event, ans, name = names[i];

var ans = typeof that[name] === 'function' && that[name](event);
if (event._isPrevented) { return ans; }
if (typeof that[name] === 'function') {
event = that._event(name, results, params, options);
reply = that[name](event);
if (event._isPrevented) { return reply; }
}

return prov(name, params, options);
});

return pzero.when(execs).then(function(ans) {
results.push.apply(results, ans);
return pzero.when(execs).then(function(local) {
results.push.apply(results, local);
return results;
});
};
Expand Down
24 changes: 24 additions & 0 deletions test/spec/logic.js
Expand Up @@ -206,6 +206,30 @@ describe('logic', function() {
expect( this.provider.getCall(0).args )
.to.eql( ['10', {a: 1}, {b: 2}] );
});

it('should call event if logic has handler', function() {
sinon.spy(this.logic, '_event');
this.logic['10'] = function() {};
this.logic._exec(['10'])();

expect( this.logic._event.calledOnce ).to.be.ok();
});

it('should pass argumetns to _event call', function() {
sinon.spy(this.logic, '_event');
this.logic['10'] = function() {};
this.logic._exec(['10'], {a: 1}, {b: 2})([1, 2]);

expect( this.logic._event.getCall(0).args )
.to.eql( ['10', [1, 2], {a: 1}, {b: 2}] );
});

it('should not call event if logic hasn\'t handler', function() {
sinon.spy(this.logic, '_event');
this.logic._exec(['10'])();

expect( this.logic._event.called ).not.to.be.ok();
});
});

});

0 comments on commit b8d406e

Please sign in to comment.