Created by a Respond object to match a request to a response:
const matcher: RequestMatcher = respond.ok().when;
Matches requests with the given method.
Parameters
method
RequesetMethod The request method to match
Returns this
respond.ok().when.method(RequestMethod.Put);
Matches requests that have the header key set
Parameters
key
string The request header key to check
Returns this
respond.ok().when.hasHeader('Auth');
Matches requests that have the header key set to the value provided
Parameters
key
string The request header key to checkvalue
string | string[] The request header value to check
Return this
respond.ok().when.hasHeader('Auth', 'Token 123ABCD');
Matches requests that have the same body
Parameters
body
any The request body object to match. Non-string bodies are automatically serialized to JSON
Return this
respond.ok().when.body({ authenticated: true });
Matches requests that have the same URL
Parameters
url
string The request URL to match
Returns this
respond.ok().when.url('/api');
Shortcuts to set URL with the GET
or DELETE
methods
Parameters
url
string The request URL to match
Returns this
respond.ok().when.get('/api');
respond.ok().when.delete('/post/123');
Shortcuts to set the URL and body with the POST
and PUT
methods
Parameters
url
string The request URL to matchbody
any The request body to match
Returns this
respond.ok().when.post('/users', { username: 'mikeryan' });
respond.ok().when.put('/posts/123', { title: 'Test' });
Create a custom assertion used to match the request
Parameters
assertion
(req: Request) => boolean Function to match the Request
Returns this
respond.ok().when.match(req => req.status === 404);