Function .use using outside value
daspedras1 opened this issue · comments
Hey @vlucas, how you doing?
I saw this issue (#478) and I tried to do something with the use
function.
I'm trying to abstract some validations, and I created a function to validate the status code. My problem is, I wanna reuse the function with multiple status, passing them in the function call.
Something like this:
function statusCodeValidation(spec, statusCode) {
return spec.expect('status', statusCode)
}
function retrieveList(status) {
return frisby.get(<endpoint here>)
.use(statusCodeValidation(status))
};
retrieveList(200);
But I'm getting this:
TypeError: spec.expect is not a function
8 |
9 | function statusCodeValidation(spec, statusCode) {
> 10 | return spec.expect('status', statusCode)
| ^
11 | }
You know how can to make this work?
Thank you so much!!!
It only works if I do this:
function statusCodeValidation(spec) {
return spec.expect('status', 200)
}
function retrieveList(status) {
return frisby.get(<endpoint here>)
.use(statusCodeValidation)
};
return function.
function statusCodeValidation(statusCode) {
// return function.
return function(spec) {
spec.expect('status', statusCode)
};
}
function retrieveList(status) {
return frisby.get(<endpoint here>)
.use(statusCodeValidation(status))
};
retrieveList(200);
Hey @H1Gdev , it worked for me.
Thanks a lot! You really helped me.