Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
I am trying to set a cookie in supertest but it does not work

I am trying to set a cookie session to a post request in supertest but I cannot. This is my test code:

const app = express();

app.set("trust proxy", true);
app.use(json());
app.use(
  cookieSession({
    signed: false,
    secure: process.env.NODE_ENV !== "test",
  })
);
   
    
    it("this is a test", async () => {
      const response = await request(app)
        .post("/api/users/current")
        .set("Cookie", [
        'express:sess=eyJqd3QiOiJleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKcFpDSTZJakV5TXpRaUxDSmxiV0ZwYkNJNkluUmxjM1JBZEdWemRDNWpiMjBpTENKcFlYUWlPakUyTkRZeE5qazVNREI5LjZybE8zODB2RG1PN0J4cFlhRERZSnBScmhrMEc2X3pvN3BBd2MxYU5rMVEifQ=='
          ])
        .send({});
    
      expect(response.get("Set-Cookie")).toBeDefined();
    });

and this test fails because response.get("Set-Cookie") is undefined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to my investigation, Supertest library is not stable. Majority developers have difficulties to set or retrieve cookies during testing.

You can take a look at this link: how to set signed cookies

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!