import request from 'supertest';
import { unsign } from 'cookie-signature';
// If your key comes from .env
import dotenv from 'dotenv';
dotenv.config();
const baseURL = 'http://localhost:3000';
const key = process.env.COOKIE_SECRET; // Set your key here. Mine comes from .env
describe('My super awesome test group', () => {
it('test some stuff', async () => {
const res = await request(app)
.get('/your-endpoint')
.set('Cookie', `myCookie=s:${sign('my value', key)}`);
expect(res.status).toBe(200);
// Do other assertions
});
});
1条答案
按热度按时间2wnc66cl1#
cookie-parser
库在幕后使用cookie-signature
库,我假设你可以访问加密密钥或cookie秘密(在.env或任何地方),没有它,你不能签署你的cookie。我使用
supertest
来处理请求。希望能有所帮助:)