import { NestedWhen } from '../errors' ; import { ApplyProp } from '../expectation/expectation' ; import { ExpectationRepository } from '../expectation/repository/expectation-repository' ; import { setActiveMock } from './map' ; import { Mock } from './mock' ; import { PendingExpectation } from '../when/pending-expectation' ; import { createProxy , Property } from '../proxy' ; export const createStub = < T > ( repo , pendingExpectation ) : Mock < T > => { const stub = createProxy < T > ( { property : ( property ) => { setActiveMock ( stub ) ; pendingExpectation . start ( repo ) ; pendingExpectation . property = property ; return createProxy ( { property : ( childProp ) => { pendingExpectation . clear ( ) ; throw new NestedWhen ( property , childProp ) ; } , apply : ( args ) => { pendingExpectation . args = args ; } , ownKeys : ( ) => { throw new Error ( 'Spreading during an expectation is not supported.' ) ; } , } ) ; } , apply : ( args ) => { setActiveMock ( stub ) ; pendingExpectation . start ( repo ) ; pendingExpectation . property = ApplyProp ; pendingExpectation . args = args ; } , ownKeys : ( ) => { throw new Error ( 'Spreading during an expectation is not supported.' ) ; } , } ) ; return stub ; } ;