1
0
Fork 0

No failure event if failures have not changed in ValidStateMonitor

* src/validate/ValidStateMonitor.js (mergeFailures): Return count of new
failures

* test/validate/ValidStateMonitorTest.js: Respective test added
master
Mike Gerwitz 2016-04-19 11:29:14 -04:00
parent 553a020554
commit ddffb4e301
2 changed files with 25 additions and 5 deletions

View File

@ -55,11 +55,10 @@ module.exports = Class( 'ValidStateMonitor' )
*/
'public update': function( data, failures )
{
var fixed = this.detectFixes( data, this._failures, failures );
var fixed = this.detectFixes( data, this._failures, failures ),
count_new = this.mergeFailures( this._failures, failures );
this.mergeFailures( this._failures, failures );
if ( this.hasFailures() )
if ( this.hasFailures() && ( count_new > 0 ) )
{
this.emit( 'failure', this._failures );
}
@ -136,10 +135,12 @@ module.exports = Class( 'ValidStateMonitor' )
* @param {Object} past past failures to merge with
* @param {Object} failures new failures
*
* @return {undefined}
* @return {number} number of new failures
*/
'virtual protected mergeFailures': function( past, failures )
{
var count_new = 0;
for ( var name in failures )
{
past[ name ] = past[ name ] || [];
@ -148,8 +149,11 @@ module.exports = Class( 'ValidStateMonitor' )
for ( var i in failures[ name ] )
{
past[ name ][ i ] = failures[ name ][ i ];
count_new++;
}
}
return count_new;
},

View File

@ -151,6 +151,22 @@ describe( 'ValidStateMonitor', function()
} )
.update( data, {} );
} );
it( 'does not trigger failure event for existing', function()
{
var called = 0;
Sut()
.on( 'failure', function()
{
called++;
} )
.update( {}, { foo: [ 'bar' ] } )
.update( {}, {} ); // do not trigger failure event
expect( called ).to.equal( 1 );
} );
} );