npm.io
0.3.0 • Published 4 years ago

@mocat/interceptor

Licence
MIT
Version
0.3.0
Deps
3
Size
66 kB
Vulns
0
Weekly
0
Stars
29

Mocat Interceptor

Intro

The part of Mocat which is used to interceptor http request.

Usage

Install dependencies:

yarn add --dev @mocat/interceptor

Then

import { eventEmitter, setupFetch, setupXHR } from '@mocat/interceptor'

// proxy http request
const resetFetch = setupFetch()
const resetXHR = setupXHR()

eventEmitter.onAny((event, value) => console.log(event, value))

// reset
resetFetch()
resetXHR()

Credits

The implementation of this module is power by the following prior art in the JavaScript ecosystem:

Caveats

  • @mocat/interceptor will replaces window.fetch and window.XMLHttpRequest with a proxy that Mocat can spy on and stub.