import * as mock from 'mock-require' ; let defaultResponse ; let languageResponse ; let lastInput ; let lastOptions ; let numTranslations ; export function reset ( ) { defaultResponse = [ 'unset' ] ; languageResponse = { } ; lastInput = '' ; lastOptions = { } ; numTranslations = 0 ; } export let translate = { translate : ( input , options ) => { lastInput = input ; lastOptions = options ; numTranslations ++ ; if ( languageResponse . hasOwnProperty ( options . to ) ) { return Promise . resolve ( languageResponse [ options . to ] ) ; } return Promise . resolve ( defaultResponse ) ; } , } ; export function setDefaultResponse ( r ) { defaultResponse = r ; } export function setResponse ( lang , r ) { languageResponse [ lang ] = r ; } export function getLastInput ( ) { return lastInput ; } export function getLastOptions ( ) { return lastOptions ; } export function getNumTranslations ( ) { return numTranslations ; } export function init ( ) { mock ( '@google-cloud/translate' , ( ) => translate ) ; }