Skip to content

Commit

Permalink
Added Notifier and Receiver Test Specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rgr-myrg committed Dec 8, 2015
1 parent ae587b8 commit 41420f6
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 321 deletions.
11 changes: 5 additions & 6 deletions dist/pattern.js
@@ -1,4 +1,4 @@
/* pattern-js v1.1.0 Tue Dec 08 2015 00:54:49 GMT-0500 (EST) */(function(w){w.Pattern=w.Pattern||{};})(window);(function($P){var TRUE = true,
/* pattern-js v1.1.0 Tue Dec 08 2015 13:00:32 GMT-0500 (EST) */(function(w){w.Pattern=w.Pattern||{};})(window);(function($P){var TRUE = true,

FALSE = false,

Expand Down Expand Up @@ -216,20 +216,22 @@ $P.Receiver = function( object ) {

receiver.notify = function( eventName, eventData ) {

if ( callOnce[ eventName ] ) {
if ( IS_FUNCTION( callOnce[ eventName ] ) ) {

FUNCTION_APPLY( callOnce[ eventName ], receiver, eventData );

delete callOnce[ eventName ];

}

if ( callbacks[ eventName ] ) {
if ( IS_FUNCTION( callbacks[ eventName ] ) ) {

FUNCTION_APPLY( callbacks[ eventName ], receiver, eventData );

}

return eventName;

};

EXEC_INIT_METHOD( receiver );
Expand All @@ -238,9 +240,6 @@ $P.Receiver = function( object ) {

};

// var r = $P.Receiver();
// r.on( "method", function() {} );

$P.Observable = function( object ) {

var observers = [],
Expand Down
2 changes: 1 addition & 1 deletion dist/pattern.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion karma.conf.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function( config ) {

// list of files / patterns to load in the browser
files: [
"dist/pattern.js",
"dist/pattern.min.js",
"test/*.js"
],

Expand Down
5 changes: 2 additions & 3 deletions src/notifier/Receiver.js
Expand Up @@ -50,13 +50,12 @@ $P.Receiver = function( object ) {

}

return eventName;

};

EXEC_INIT_METHOD( receiver );

return receiver;

};

// var r = $P.Receiver();
// r.on( "method", function() {} );
64 changes: 64 additions & 0 deletions test/Notifier.Spec.js
@@ -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" );

});

});
65 changes: 65 additions & 0 deletions test/Receiver.Spec.js
@@ -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" );

});

});

0 comments on commit 41420f6

Please sign in to comment.