The port the server is running on.
This will throw an error if read before the server is started.
The environment variables typically needed to use this server as a proxy, in a format you can add to your environment straight away.
This will throw an error if read before the server is started.
process.env = Object.assign(process.env, mockServer.proxyEnv)
The root URL of the server.
This will throw an error if read before the server is started.
Get a builder for a mock rule that will match any requests on any path.
Get a builder for a mock rule that will match DELETE requests for the given path.
Enable extra debug output so you can understand exactly what the server is doing.
Get a builder for a mock rule that will match GET requests for the given path.
Subscribe to hear about request details as they're received.
This is only useful in some niche use cases, such as logging all requests seen by the server independently of the rules defined.
The callback will be called asynchronously from request handling. This function returns a promise, and the callback is not guaranteed to be registered until the promise is resolved.
Get a builder for a mock rule that will match OPTIONS requests for the given path.
This can only be used if the cors option has been set to false.
If cors is true (the default when using a remote client, e.g. in the browser), then the mock server automatically handles OPTIONS requests to ensure requests to the server are allowed by clients observing CORS rules.
You can pass {cors: false} to getLocal/getRemote to disable this behaviour,
but if you're testing in a browser you will need to ensure you mock all OPTIONS
requests appropriately so that the browser allows your other requests to be sent.
Get a builder for a mock rule that will match PATCH requests for the given path.
Get a builder for a mock rule that will match POST requests for the given path.
Get a builder for a mock rule that will match PUT requests for the given path.
Reset the stored rules. Most of the time it's better to start & stop the server instead, but this can be useful in some special cases.
Start a mock server.
Specify a fixed port if you need one. If you don't, a random port will be chosen, which
you can get later with .port, or by using .url and .urlFor(path) to generate
your URLs automatically.
Stop the mock server and reset the rules.
The URL for a given path on the server.
This will throw an error if read before the server is started.
Generated using TypeDoc
A mockttp instance allow you to start and stop mock servers and control their behaviour.
Call
.start()to set up a server on a random port, use methods like.get(url),.post(url)and.anyRequest()to get a MockRuleBuilder and start defining mock rules. Call.stop()when your test is complete.