artificial
Inject fake HTTP request/response into an Express server. This is a port of hapi's shot
module, adapted to work with Express. artificial
allows fake responses to be injected into a server without first binding to a port. This simplifies testing.
Basic Usage
'use strict';const Artificial = ;const Express = ;const app = ; ; // Create the app.inject() method. app; app;
API
artificial
exports a single function that is used to add a single injection method to an Express app.
Artificial(app [, method])
- Arguments
app
(object) - An Express application.method
(string) - The name of the method to attach toapp
. Optional. Defaults to'inject'
, meaning thatapp.inject()
is created.
- Returns
app
(object) - The same Express application asapp
.
Defines an injection method on an Express server. By default, the method's name is inject()
. This method injects a request into the server, simulating an incoming HTTP request without using sockets. Injection is useful for testing purposes, as well as for invoking routing logic internally without the overhead and limitations of the network stack.