1

The related question Cant test DELETE method using mocha and supertest and its current two answers didn't solved my issue :(

The following is the test definition:

api = supertest(url);

describe('when OPTIONS', function () {
    it('should return only method GET', function (done) {
      api
        .options('/')
        .expect('Allow', 'GET')
        .expect(200, done);
    });
  });

Its keeping triggering the following error:

Uncaught TypeError: Cannot read property 'header' of undefined
      at _stream_readable.js:944:16

and when:

 api
        .options('/')
        .end(function(error,res){
          if (error) return done(error);
          done()
        });

It says:

SyntaxError: Unexpected token G
      at Object.parse (native)
      at _stream_readable.js:944:16

I already tried a lot of things without being able to make this work.

I 'm using supertest ^1.0.1 and it worked fine with version ~0.13.0.

Related issue at https://github.com/visionmedia/supertest/issues/272

Thanks

Community
  • 1
  • 1
Diosney
  • 10,520
  • 15
  • 66
  • 111

1 Answers1

0

I already detected the issue, it was that in the API I was returning an OPTIONS response with Content-Type: application/json but the body was an invalid JSON (it was GET,HEAD).

Diosney
  • 10,520
  • 15
  • 66
  • 111