ladjs / supertest

🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Headers are not set on Node16

fetis opened this issue · comments

I have a simple test checking CORS functionality.

    app.js
...
    const origin = req.headers.origin || '';
    // accessing origin and doing the checks
        await request
            .get('/test')
            .set('Origin', 'https://origin.com')
            .expect('Access-Control-Allow-Origin', 'https://origin.com')
            .expect(200);

It works perfectly in Node14, but after the upgrade to Node16 app fails with Cannot read properties of undefined (reading 'origin') and headers object is simply undefined

it was a problem on my side. I was doing restructuring like

const newRequest = { 
  ..req,
 // my stuff
}