1

I have a post route which accepts string. Here the input is JSON as string so I convert that string to JSON using JSON.parse() in my route logic. Now when I am testing it using Lab how can I give JSON string as payload.

Code;

lab.test('dummy test', done => {
    const options = {
      method: 'POST',
      url: '/test',
      payload: {name: 'john', age: 30},
    };
    server.inject(options, response => {
      Code.expect(response.statusCode).to.equal(200);
      done();
    });
  });

If I use like this then in application I am getting error while parsing the string to JSON as this is already a JSON object. Here how can I give this payload as string. I used

JSON.stringify({name: 'john', age: 30})

but did not work.

simon-p-r
  • 3,623
  • 2
  • 20
  • 35
Anil Kumar R
  • 283
  • 1
  • 4
  • 12

0 Answers0