Ray Ray - 1 year ago 111
Javascript Question

How to verify if either 200 or 201 status code in Frisby Test

I'm using

v0.8.5 and
. With
there's the following to assert for expected return http status code:

f = frisby.create(/*stuff....*/);

This works fine if the endpoint has a single expected status, but in some cases (like a POST endpoint) you might get back a
for created or a
if the resource is already present.

Is there any way in frisby to check for on of several acceptable response status codes?

Ray Ray
Answer Source

Ok, found an easy way to do this using the after() and native jasmine matching functionaly.

The general idea is since Frisby is asynchronous, you need to check the result after it's been tossed and caught. Inside the raw result, you can manually verify the status code against a regular expression, which in this case is either 200 or 201:

 f = frisby.create(/*stuff....*/);
 // ...
 // ... 

 f.after( function(err, res, body) {

     //Look for either a 200 or 201


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download