import { CreateResponse , OnSerializedRequest , } from "unmock-core/dist/interfaces" ; import replaceOpenAndReturnOriginal from "./xmlhttprequest" ; export { replaceOpenAndReturnOriginal } ; let xmlhttprequestInterceptor ; export class XMLHttpRequestInterceptor { private originalXMLHttpRequestOpen : ( method : string , url : string , async ? : boolean , username ? : string | null , password ? : string | null ) => void ; constructor ( onSerializedRequest ) { this . originalXMLHttpRequestOpen = replaceOpenAndReturnOriginal ( onSerializedRequest ) ; } public disable ( ) { if ( this . originalXMLHttpRequestOpen ) { XMLHttpRequest . prototype . open = this . originalXMLHttpRequestOpen ; } } } export default { param onSerializedRequest on ( onSerializedRequest ) { this . off ( ) ; xmlhttprequestInterceptor = new XMLHttpRequestInterceptor ( onSerializedRequest ) ; return xmlhttprequestInterceptor ; } , /**
     * Stop intercepting `xmlhttprequest`, restore original `xmlhttprequest`.
     */ off ( ) { if ( xmlhttprequestInterceptor ) { xmlhttprequestInterceptor . disable ( ) ; xmlhttprequestInterceptor = undefined ; } } , } ;