Frisby.JS - unexpected token ( when sending a POST with json

1k views Asked by At

I'm getting the following error,

 Error: Error parsing JSON string: Unexpected token <
    Given: <html>
<body>
<p>
  <b>400.</b> Invalid json request: numOfDays=1&amp;checkInDate=2013-04-10.
Make sure that key names and text values are quoted with "
</p>
</body>
</html>
Stacktrace:

using the following code:

var frisby = require('frisby');

  frisby.create('Ensure proper values in specified keys')
  .post('http://localhost:9090/bookRoom', {"numOfDays": 1 , "checkInDate":"2013-04-10"})
    .expectJSON({
        "checkInDate": "2013-04-10",
        "checkOutDate": "2013-04-11",
        "totalPrice": 130
    })
.toss()

I'm trying to pass this JSON - {"numOfDays": 1 , "checkInDate":"2013-04-10"}

EDIT:

It seems that the JSON being passed is in the following format. How do I get rid of those backslashes?

Handling booking request: "{\"numOfDays\":\"1\",\"checkInDate\":\"2013-04-10\"}"
2

There are 2 answers

2
Andras On

I've just run into the same problem but I used different parameters for post. Precisely I added {json: true} as 3rd parameter and after a few minutes of struggling I removed it and it worked.

It looks your case might be the other way around. Try to put that 3rd parameter in the post method call and hope the best.

Related documentation: API docs

1
Vance Lucas On

Author of Frisby.js here. Please update to Frisby v0.8.5 - this is due to a change in the "request" module that Frisby depends on and uses.