import { Expectation , ReturnValue } from './expectation' ; import { ExpectationRepository } from './repository/expectation-repository' ; import { ExpectationFactory , PendingExpectation , } from '../when/pending-expectation' ; import { Property } from '../proxy' ; export class OneUseAlwaysMatchingExpectation implements Expectation { setInvocationCount = ( ) => { } ; toJSON = ( ) => 'always matching' ; args = undefined ; min = 1 ; max = 1 ; property = 'bar' ; returnValue = { value : 42 } ; matches = ( ) => true ; } export class SpyExpectation implements Expectation { max = - 1 ; min = - 1 ; setInvocationCount = ( min , max ) => { this . min = min ; this . max = max ; } ; toJSON = ( ) => 'spy expectation' ; constructor ( public property , public args , public returnValue ) { } matches = ( ) => false ; } export const spyExpectationFactory = ( property , args , returnValue ) => new SpyExpectation ( property , args , returnValue ) ; export class SpyPendingExpectation implements PendingExpectation { toJSON = ( ) => 'spy pending expectation' ; public argsCalledWith : any [ ] | undefined ; public clearCalled = false ; public finishCalledWith : ReturnValue | undefined ; public propertyCalledWith : Property | undefined ; public startCalledWith : ExpectationRepository | undefined ; set args ( args ) { this . argsCalledWith = args ; } clear ( ) { this . clearCalled = true ; } finish ( returnValue ) { this . finishCalledWith = returnValue ; return new OneUseAlwaysMatchingExpectation ( ) ; } set property ( value ) { this . propertyCalledWith = value ; } start ( repo ) { this . startCalledWith = repo ; } } export class MatchingPropertyExpectation implements Expectation { constructor ( public property , public returnValue ) { } args = undefined ; max = 1 ; min = 1 ; matches = ( args ) => args === undefined ; setInvocationCount ( min , max ) { this . min = min ; this . max = max ; } toJSON = ( ) => 'matching property' ; } export class MatchingCallExpectation implements Expectation { constructor ( public property , public returnValue ) { } args = [ ] ; max = 1 ; min = 1 ; setInvocationCount ( min , max ) { this . min = min ; this . max = max ; } matches = ( args ) => ! ! args ; toJSON = ( ) => 'matching call' ; } export class NotMatchingExpectation extends MatchingCallExpectation { matches = ( ) => false ; toJSON = ( ) => 'not matching' ; }