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 addedmaster
parent
553a020554
commit
ddffb4e301
|
@ -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;
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -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 );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue