DataValidator: Always clear store state
commit
e0c2e4dc86
|
@ -193,7 +193,8 @@ module.exports = Class( 'DataValidator',
|
|||
{
|
||||
if ( data === undefined )
|
||||
{
|
||||
return Promise.resolve( [] );
|
||||
// it's important that we don't re-use previous state
|
||||
return store.clear().then( [] );
|
||||
}
|
||||
|
||||
const mapf = ( subkey !== undefined )
|
||||
|
|
|
@ -212,6 +212,45 @@ describe( 'DataValidator', () =>
|
|||
.validate( {} )
|
||||
).to.eventually.be.rejectedWith( expected_e );
|
||||
} );
|
||||
|
||||
|
||||
[
|
||||
[],
|
||||
[ {} ],
|
||||
[ undefined ],
|
||||
[ undefined, {} ],
|
||||
[ undefined, undefined ],
|
||||
[ {}, undefined ],
|
||||
].forEach( args => it( 'does not re-use previous store state', () =>
|
||||
{
|
||||
const bvalidator = createMockBucketValidator();
|
||||
const vmonitor = ValidStateMonitor();
|
||||
const dep_factory = createMockDependencyFactory();
|
||||
|
||||
const stores = {
|
||||
store: MemoryStore(),
|
||||
bstore: sinon.createStubInstance( MemoryStore ),
|
||||
cstore: sinon.createStubInstance( MemoryStore ),
|
||||
};
|
||||
|
||||
const { bstore, cstore } = stores;
|
||||
|
||||
const cleared = which =>
|
||||
{
|
||||
cleared[ which ] = true;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
bstore.clear = () => cleared( 'b' );
|
||||
cstore.clear = () => cleared( 'c' );
|
||||
|
||||
const sut = Sut( bvalidator, vmonitor, dep_factory, () => stores );
|
||||
|
||||
return sut.validate.apply( sut, args )
|
||||
.then( () =>
|
||||
expect( cleared.b && cleared.c ).to.be.true
|
||||
);
|
||||
} ) );
|
||||
} );
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue