axios-with-cookies
Version:
Fork of axios-cookiejar-support with configurable http(s)-agent
43 lines (42 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = __importDefault(require("ava"));
const axios_1 = __importDefault(require("axios"));
const tough_cookie_1 = require("tough-cookie");
const __1 = require("../");
const helpers_1 = require("./helpers");
ava_1.default.before(() => {
(0, __1.wrapper)(axios_1.default);
});
ava_1.default.serial('should store cookies to cookiejar when using instance', async (t) => {
const { port } = await (0, helpers_1.createTestServer)([
(_req, res) => {
res.setHeader('Set-Cookie', 'key=value');
res.end();
},
]);
const jar = new tough_cookie_1.CookieJar();
const client = axios_1.default.create({ jar });
await client.get(`http://localhost:${port}`);
const cookies = await jar.getCookies(`http://localhost:${port}`);
t.like(cookies, {
0: { key: 'key', value: 'value' },
});
t.plan(1);
});
ava_1.default.serial('should send cookies from cookiejar when using instance', async (t) => {
const { port } = await (0, helpers_1.createTestServer)([
(req, res) => {
t.is(req.headers['cookie'], 'key=value');
res.end();
},
]);
const jar = new tough_cookie_1.CookieJar();
const client = axios_1.default.create({ jar });
await jar.setCookie('key=value', `http://localhost:${port}`);
await client.get(`http://localhost:${port}`);
t.plan(1);
});