DefinitelyTyped/types/cookie/cookie-tests.ts
Piotr Błażejewicz (Peter Blazejewicz) 70307bbf23
update(cookie): update to 0.4 and minor changes (#43968)
* update(cookie): update to 0.4 and minor changes

- version bump (no api shape change)
- documentation update
- parameter names align with package
- minor fixes in JSDoc format

https://github.com/jshttp/cookie/releases/tag/v0.4.0

Thanks!

* update(cookie): minor change

Correction from 0.4.1 for `maxAge` causing `TypeError` exception:
https://github.com/jshttp/cookie/compare/v0.4.0...v0.4.1

Thanks!
2020-05-13 08:46:24 -07:00

35 lines
941 B
TypeScript

import cookie = require('cookie');
function test_serialize(): void {
let retVal: string;
retVal = cookie.serialize('foo', 'bar');
retVal = cookie.serialize('foo', 'bar', { httpOnly: true });
retVal = cookie.serialize('foo', 'bar', { sameSite: 'none' });
retVal = cookie.serialize('foo', 'bar', { sameSite: 'lax' });
}
function test_parse(): void {
let retVal: { [key: string]: string };
retVal = cookie.parse('foo=bar; bar=baz;');
retVal = cookie.parse('foo=bar; bar=baz', { decode: x => x });
}
function test_options(): void {
const serializeOptions: cookie.CookieSerializeOptions = {
encode: (x: string) => x,
path: '/',
expires: new Date(),
maxAge: 200,
domain: 'example.com',
secure: false,
httpOnly: false,
sameSite: 'strict',
};
const parseOptios: cookie.CookieParseOptions = {
decode: (x: string) => x,
};
}