import { BaseRepository , CountableExpectation } from './base-repository' ; import { Expectation } from '../expectation' ; import { ExpectationRepository } from './expectation-repository' ; import { Property } from '../../proxy' ; /**
 * Always return something, even if no expectations match.
 *
 * WARNING: this is in development, do not use
 */ export class WeakRepository extends BaseRepository implements ExpectationRepository { private repeating = new Map < Property , boolean > ( ) ; protected getValueForUnexpectedCall = ( ) => null ; protected getValueForUnexpectedAccess = ( ) => ( { value : ( ) => null } ) ; protected consumeExpectation ( expectation ) { const { property , max } = expectation . expectation ; const expectations = this . expectations . get ( property ) ! ; if ( expectation . matchCount === max ) { if ( expectations . length === 1 ) { this . repeating . set ( property , true ) ; } else { this . expectations . set ( property , expectations . filter ( ( e ) => e !== expectation ) ) ; } } } add ( expectation ) { const { property } = expectation ; const expectations = this . expectations . get ( property ) ; if ( expectations ) { if ( expectations . length === 1 && this . repeating . get ( property ) ) { this . repeating . set ( property , false ) ; this . expectations . set ( property , [ ] ) ; } } super . add ( expectation ) ; } }