forked from mroderick/PubSubJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a subscription after executed only once
- Loading branch information
Showing
2 changed files
with
47 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var PubSub = require('../src/pubsub'), | ||
TestHelper = require('../test/helper'), | ||
assert = require('referee').assert, | ||
sinon = require('sinon'); | ||
|
||
|
||
describe( 'subscribeOnce method', function() { | ||
|
||
it( 'should return PubSub', function() { | ||
var func = function(){ return undefined; }, | ||
message = TestHelper.getUniqueString(), | ||
pubSub = PubSub.subscribeOnce( message , func ); | ||
assert.same( pubSub, PubSub ); | ||
} ); | ||
|
||
it( 'must be executed only once', function() { | ||
|
||
var topic = TestHelper.getUniqueString(), | ||
spy = sinon.spy(); | ||
|
||
PubSub.subscribeOnce( topic, spy ); | ||
for ( var i = 0; i < 3; i++ ) { | ||
PubSub.publishSync( topic, TestHelper.getUniqueString() ); | ||
} | ||
|
||
assert( spy.calledOnce ); | ||
|
||
} ); | ||
|
||
} ); |