Members
(static) stub
Access pre-defined "stub" mocking commands to make templated invocations of "createMapping".
- Source:
- See:
(static) find
Access pre-defined "find" mocking commands to make templated invocations of "findRequests".
- Source:
- See:
Methods
(static) init(options)
Initialize the Mock Cmdr session. If cmdDir is specified then commands will be loaded.
Parameters:
Name | Type | Description |
---|---|---|
options |
InitOptions |
- Source:
- See:
(static) reset()
Reset mockCmdr configuration. This does not remove stub mappings from the remote mock server.
(static) defineCmd(cmd)
Define a templated mocking command that will be available via
mockCmdr.{type}.{path}
or mockCmdr.{type}.{name}
. When the command is
invoked then createMapping()
or findRequests()
will be called with the
output of the command's template function.
Parameters:
Name | Type | Description |
---|---|---|
cmd |
Command |
Example
defineCmd({
type: 'stub',
path: [ 'user', 'create' ],
template: (user) => {
return {
request: {
method: 'POST',
urlPath: '/api/user'
},
response: {
status: 201,
jsonBody: {
id: user.id,
name: user.name,
},
},
};
}
})
// invoked as:
await mockCmdr.stub.user.create(user);
(static) loadCmds(cmdDir)
Load all "find" and "stub" mocking commands by searching recursively within cmdDir.
The discovered commands will be passed to defineCmd()
using the camel
cased file names as the command path. Modules found within a "find"
directory are treated as "find" commands and modules found within a
"stub" directory are treated as "stub" commands. Modules not within a
"find" or "stub" directory are ignored.
Any intermediate directories other than "find" and "stub" will be treated as namespaces. Namespaces can be arbitrarily deep and are also camel cased. The "find" and "stub" dirs are excluded from the namespace and need not appear at the top level allowing related commands to be grouped appropriately.
Parameters:
Name | Type | Description |
---|---|---|
cmdDir |
string |
- Source:
- See:
Examples
// [cmdDir]
// |
// |- stub
// | |- user-create.js
// | |- user-get-by-id.js
// |
// |- find
// |
// |- user-create-by-email.js
// Resulting commands:
mockCmdr.stub.userCreate()
mockCmdr.stub.userGetById()
mockCmdr.find.userCreateByEmail()
// [cmdDir]
// |
// |- my-service
// |
// |- stub
// |
// |- user
// |
// |- create.js
// |- get-by-id.js
// Resulting commands:
mockCmdr.stub.myService.user.create()
mockCmdr.stub.myService.user.getById()
(static) createMapping(mapping)
Call the Wiremock create mapping API.
See also: Wiremock API Docs.
Parameters:
Name | Type | Description |
---|---|---|
mapping |
WiremockStubMapping |
(static) findRequests(criteria) → {Array.<WiremockRequest>}
Call the Wiremock find requests API
See also: Wiremock API Docs.
Parameters:
Name | Type | Description |
---|---|---|
criteria |
WiremockRequestCriteria |
(static) cleanUp()
Remove all stub mappings that have been created by the current session. This does not modify mockCmdr configuration.