k6 community forum

K6 check() response code between 2 values

 check(res, {
"is status 202": (r) => r.status === 409

});

I want to verify whether response code is either of 202 or 409. Any one of them is allowed. How to verify this in K6 ?

For example, in postman, I can use
pm.expect(pm.response.code).to.be.oneOf([202, 409]);

Hi @vishal.lanke,
I can’t find this mentioned explicitly somewhere in the documentation or the api spec, but the second argument of the check is a map of string names to function checks.

(r) => r.status == 409 is the same as function( r ) { return r.status == 409 }

So in your particular example you can go with (r) => r.status == 409 || r.status == 202