import { MissingWhen , UnfinishedExpectation } from '../errors' ; import { Expectation , ReturnValue } from '../expectation/expectation' ; import { ExpectationRepository } from '../expectation/repository/expectation-repository' ; import { printWhen } from '../print' ; import { Property } from '../proxy' ; export type ExpectationFactory = ( property : Property , args : any [ ] | undefined , returnValue : ReturnValue ) => Expectation ; export interface PendingExpectation { start ( repo ) : void ; finish ( returnValue ) : Expectation ; clear ( ) : void ; property : Property ; args : any [ ] | undefined ; /**
     * Used by `pretty-format`.
     */ toJSON ( ) : string ; } export class RepoSideEffectPendingExpectation implements PendingExpectation { private _repo : ExpectationRepository | undefined ; private _args : any [ ] | undefined ; private _property : Property = '' ; constructor ( private createExpectation ) { } start ( repo ) { if ( this . _repo ) { throw new UnfinishedExpectation ( this ) ; } this . clear ( ) ; this . _repo = repo ; } set property ( value ) { this . _property = value ; } set args ( value ) { this . _args = value ; } finish ( returnValue ) { if ( ! this . _repo ) { throw new MissingWhen ( ) ; } const expectation = this . createExpectation ( this . _property , this . _args , returnValue ) ; this . _repo . add ( expectation ) ; this . clear ( ) ; return expectation ; } clear ( ) { this . _repo = undefined ; this . _args = undefined ; this . _property = '' ; } toJSON ( ) { return printWhen ( this . _property , this . _args ) ; } }