0

I try to do a GET if a error occurs in a previous POST with supertest. The problem is that I am unable to use GET. This is my code:

bookId = await request(app).post("/books/add-one-book").send({
                "name":"bookTest",
                "chapters": 1
        })

if (bookId === undefined) {
   const allBooks = await request(app)
        .get("/books/all-books")
        .set({
               Authorization: `Bearer ${token}`
          })
bookId = allBooks;
...

The warning says:

Argument type string is not assignable to parameter type "set-cookie".

The warning for set is:

Unresolved function or method set()

What did I do wrong? I think supertest don't see the right GET... But I have seen a lot of example on the web and all of them use get like this. Do you see something? Thanks.

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
mathdx
  • 45
  • 6

1 Answers1

0

I guess you've used ESM import..
There is no default export in 'supertest' module.
Try to import it in this way:

import { agent as request } from 'supertest'
Scrapy
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 09 '23 at 07:20