@panintelligence/document.cookie.mock

0.1.6 • Public • Published

Cookie Mock Logo Cookie Mock

An implementation of document.cookie to use in node that behaves just like document.cookie on a browser.

Useful for testing!

Features

Properties Implemented
Get behaviour Yes
Set behaviour Yes
expires Yes
max-age Yes
domain Planned
path Planned
secure Ideas welcome
samesite Ideas welcome

Installation

npm i @panintelligence/document.cookie.mock

How to use

const DocumentCookie = require('document.cookie.mock');

const document = new DocumentCookie();

document.cookie = "key=value; max-age=3600";
console.log(document.cookie); // "key=value"

document.cookie = "key2=value2";
console.log(document.cookie); // "key=value; key2=value2"

document.cookie = "key=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
console.log(document.cookie); // "key2=value2"

Or if you want to plug it into your own document mock...

const DocumentCookie = require('document.cookie.mock');

class Document {
    constructor(){
        // ...
        this._cookie=new DocumentCookie();
        // ...
    }
    
    // ...

    get cookie(){
        return this._cookie;
    }

    set cookie(v){
        return this._cookie = v;
    }

    // ...
}

Development

git clone git@github.com:Panintelligence/document.cookie.mock.git
cd document.cookie.mock
npm install

Readme

Keywords

Package Sidebar

Install

npm i @panintelligence/document.cookie.mock

Weekly Downloads

157

Version

0.1.6

License

GPL-3.0-or-later

Unpacked Size

66.2 kB

Total Files

10

Last publish

Collaborators

  • dosaki