-
Notifications
You must be signed in to change notification settings - Fork 32
Missing return of embedded promise into retrieveRecordedRequestAndResponses #172
Copy link
Copy link
Open
Description
Describe the issue
When calling retrieveRecordedRequestsAndResponses and trying to out the result from the promise, the data remains unchanged, due to inverted execution code ( classic promise issue ).
What you are trying to do
Trying to out the result from the promise...
MockServer version
5.15.0
To Reproduce
try this code :
let records: HttpRequestAndHttpResponse[] = [];
await mockServerClient("localhost", 1080)
.retrieveRecordedRequestsAndResponses({})
.then((rs: HttpRequestAndHttpResponse[]) => {
console.log('Inside, my data are there : ' + JSON.stringify(rs));
records = rs;
});
console.log('Outside, my data array is empty :-( ' + JSON.stringify(records));
- How you are running MockServer (i.e maven plugin, docker, etc)
in an express instance (but not related to the bug) - Code you used to create expectations
there is no expectations, only recording requests and trying to get them after - What error you saw
no error ( but .catch does related to the missing return )
Expected behaviour
The recordedRequestAndResponses behaves as the others functions, regarding promise execution. Then the result to be passed outside the promise of my call.
** Fix proposed **
Simply add return into retrieveRecordedRequestsAndResponses for the makeRequest call, as the other functions have.
var retrieveRecordedRequestsAndResponses = function (pathOrRequestMatcher) {
return {
then: function (sucess, error) {
return makeRequest(host, port, "/mockserver/retrieve?type=REQUEST_RESPONSES&format=JSON", addDefaultRequestMatcherHeaders(pathOrRequestMatcher))
.then(function (result) {
sucess(result.body && JSON.parse(result.body));
}, function (err) {
error(err);
});
}
};
};```
Thank you
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels