-
Notifications
You must be signed in to change notification settings - Fork 1
You can find examples of the API calls in test/e2e/vanilli-test.js.
The functions below operate on the vanilli instance itself.
vanilli.stub(stub1, stub2, ... , stubX);
Registers one or more stubs.
vanilli.stubDefault(stub1, stub2, ... , stubX);
Identical to vanilli.stub
except that it assigns a very high priority
value to each stub (thus ensuring that the stub(s) ONLY matches if no other stub matches - see below for more info).
vanilli.expect(stub1, stub2, ... , stubX);
Registers one or more stubs as expectations. (See 'Stubs vs Expectations' section below.)
vanilli.onGet(url[, options]);
Returns a new stub that will match against an incoming GET request with a relative URL matching that specified. Further matching criteria can be specified via the options object. The following snippet illustrates all available options:
{
contentType: <string or RegExp>,
body: <string, object or RegExp>,
query: {
param1: <string or RegExp>,
...
paramX: <string or RegExp>
},
headers: {
header1: <string or RegExp>,
...
headerX: <string or RegExp>
},
priority: 0,
times: 2
}
NOTES:
- If a
body
is specified then acontentType
MUST be specified. - The
times
of the stub indicates the maximum number of times the stub will be matched. - The
priority
of the stub indicates the precedence of the stub over other stubs matching the same request: whichever stub has the lowest priority value "wins". By default a stub has the priority 0. - Note the convenience method
stubDefault
that automatically assigns a very high value to a stub (thus ensuring that it only matches if no other stub matches).
As for vanilli.onGet
except that the HTTP method for the stub is PUT.
As for vanilli.onGet
except that the HTTP method for the stub is POST.
As for vanilli.onGet
except that the HTTP method for the stub is DELETE.
vanilli.listen(port);
Starts the vanilli REST server listening on the specified port.
vanilli.stop();
Stops the vanilli REST server.
vanilli.verify();
Verifies that the expectations currently registered with vanilli have been met. If verification fails a single error is thrown detailing all unmet expectations.
vanilli.clear();
Clears vanilli down of all stubs and expectations.
var captureDetails = vanilli.getCaptures(captureId);
Gets details of the requests captured against the specified captureId. (See stub.capture
.)
Legacy version returning just the last capture - use vanilli.getCaptures
instead.
The functions below operate on an instance of a stub returned by one of the vanilli.onVERB
functions.
stub.capture(captureId);
Indicates that vanilli should store the details of the request that is eventually matched against
the stub. The specified captureId can then be used as a handle to vanilli.getCapture
to pull
those details back for asserting on.
stub.wait(milliseconds);
Indicates that when vanilli matches this stub against an incoming request it should wait the specified number of milliseconds before responding with the stubbed response.
stub.respondWith(status[, options]);
Adds details of the response to the stub. At minimum, a status code can be specified; however, more details for the response can be specified via the options. The following snippet illustrates all options.
{
contentType: <string>,
body: <string or object>,
headers: {
header1: <string>,
...
headerX: <string>
}
}
NOTE: If a body
is specified then a contentType
MUST be specified.
If specified (e.g. onGet("/some/url").respondWith(200).anyTimes()
) the stub will be matched any number of times against incoming requests. Note that, as you would expect, this has NO effect on expectations.