Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Notifier and Receiver Test Specs
- Loading branch information
Showing
8 changed files
with
146 additions
and
321 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,64 @@ | ||
describe( "Pattern.Notifier", function() { | ||
|
||
var notifier = Pattern.Notifier(); | ||
|
||
it( "Notifier should be a Constructor Function", function() { | ||
|
||
expect( typeof Pattern.Observer ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Notifier should create an Object", function() { | ||
|
||
expect( typeof notifier ).toBe( typeof {} ); | ||
|
||
}); | ||
|
||
it( "Notifier.addReceiver should be a Function", function() { | ||
|
||
expect( typeof notifier.addReceiver ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Notifier.addReceiver should add a receiver and return an Array of receivers", function() { | ||
|
||
var receivers = notifier.addReceiver( Pattern.Receiver() ); | ||
expect( receivers.length ).toEqual( 1 ); | ||
|
||
}); | ||
|
||
it( "Notifier.removeReceiver should be a Function", function() { | ||
|
||
expect( typeof notifier.removeReceiver ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Notifier.removeReceiver should remove a receiver and return an Array of receivers", function() { | ||
|
||
var receiver = Pattern.Receiver({}), | ||
|
||
receivers = notifier.addReceiver( receiver ), | ||
|
||
size = receivers.length, | ||
|
||
array = notifier.removeReceiver( receiver ); | ||
|
||
expect( array.length ).toEqual( size - 1); | ||
|
||
}); | ||
|
||
it( "Notifier.notify should send event and data and notify the receiver's callback Function", function() { | ||
|
||
var result, receiver = Pattern.Receiver(); | ||
|
||
receiver.on( "sendMessage", function( msg ) { result = msg; } ); | ||
|
||
notifier.addReceiver( receiver ); | ||
|
||
notifier.notify( "sendMessage", "a test message" ); | ||
|
||
expect( result ).toEqual( "a test message" ); | ||
|
||
}); | ||
|
||
}); |
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,65 @@ | ||
describe( "Pattern.Receiver", function() { | ||
|
||
var receiver = Pattern.Receiver(); | ||
|
||
it( "Receiver should be a Constructor Function", function() { | ||
|
||
expect( typeof Pattern.Observer ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver should create an Object", function() { | ||
|
||
expect( typeof receiver ).toBe( typeof {} ); | ||
|
||
}); | ||
|
||
it( "Receiver.on should be a Function", function() { | ||
|
||
expect( typeof receiver.on ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver.on should return an Object of callbacks", function() { | ||
|
||
var callbacks = receiver.on( "testMethod", function(){} ); | ||
|
||
expect( typeof callbacks ).toBe( typeof {} ); | ||
expect( typeof callbacks.testMethod ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver.once should be a Function", function() { | ||
|
||
expect( typeof receiver.once ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver.on should return an Object of callbacks", function() { | ||
|
||
var callbacks = receiver.once( "testMethod", function(){} ); | ||
|
||
expect( typeof callbacks ).toBe( typeof {} ); | ||
expect( typeof callbacks.testMethod ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver.notify should be a Function", function() { | ||
|
||
expect( typeof receiver.notify ).toBe( typeof function(){} ); | ||
|
||
}); | ||
|
||
it( "Receiver.notify should execute a callback Function", function() { | ||
|
||
var result; | ||
|
||
receiver.on( "sendMessage", function( msg ){ result = msg; } ); | ||
|
||
receiver.notify( "sendMessage", "a message" ); | ||
|
||
expect( result ).toEqual( "a message" ); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.