Closed SemyenSoldatenko closed 8 years ago
There is a retrieve
endpoint that can be used to retrieve a list of the requests that have been submitted. It takes a request matcher so you can retrieve only the requests you are interested in then interrogate them in any way you like. This is the only existing alternative to the verify
endpoint. However I am currently extending the javascript client to support the retrieve
endpoint. It should be done in the next couple of days. Currently this endpoint only exists on the server side.
In addition longer term I will support function callbacks when a request is matched on the server side so you will be able to perform any complex logic you want for each request including verifying the request parameters. This is however a bigger piece of work that involves using websockets and so will take a bit longer before it is available. I've done some work on this but I want to re-write the ruby client first.
Which client are you using? The browser javascript client or the node javascript client?
It is "A node client for the MockServer" "1.0.6"
ok I have finished implementing this for the browser javascript client, and I'm halfway through doing this for the node client. The node client takes a little longer as the unit tests are more painful with all the promise callbacks.
If you want to retrieve the exact requests that were sent so that you can make any assertion you can use the retrieveRequests
function, for example in nodeunit
the code might look as follows:
var client = mockServerClient("localhost", 1080);
client.retrieveRequests("/somePathOne").then(function (requests) {
// then
test.equals(requests.length, 4);
// first request
test.equals(requests[0].path, '/somePathOne');
test.equals(requests[0].method, 'POST');
test.equals(requests[0].body, 'someBody');
// second request
test.equals(requests[1].path, '/somePathOne');
test.equals(requests[1].method, 'GET');
test.done();
}, function () {
test.ok(false, "should have sent correct request");
test.done();
});
The retrieveRequests
method takes a request matcher object, a string path matcher or no parameter to retrieve all.
As follows:
// object matcher
client.retrieveRequests({
"httpRequest": {
"path": "/.*"
}
}).then(function (requests) {
// do something with requests
});
// path matcher
client.retrieveRequests("/.*").then(function (requests) {
// do something with requests
});
// no parameters
client.retrieveRequests().then(function (requests) {
// do something with requests
});
This was fixed for the node client in in https://github.com/jamesdbloom/mockserver-client-node/commit/531a8e5608e7230baf5d01e222de5257367fc073
:+1: Thank you.
How to test which parameters was supplied by code under the test?
Please don't offer to use query string matcher when i configure responst in mockSimpleResponse. Because i need clear answer when test fail. Like
expected 'undefined' to be 'bar'
. Not likerequest blah-blah-blah expected called 1 times but was called 0 times
. Thats not true.