1.0.1 • Published 7 years ago

ec.cookie-mock v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

ec.cookie-mock

Mock implementation for document.cookie. By entrecode.

npm version Build Status

You can use this for testing cookie handling in your project. Simple add it like shown in the usage example.

Installation

npm i --save cookie-mock

Usage

document = new CookieMock();

const now = new Date();
const future = new Date(now.now() + 60000) // in 60 seconds
const past = new Date(now.now() - 60000) // before 60 seconds

// add a new cookie
document.cookie = `cookie=hazelnut; expires=${future.toUTCString()}; path=/mouth; secure`;
console.log(document.cookie); // cookie=hazelnut; expires=Fri, 26 Jan 2017 12:01:00 GMT; path=/mouth; secure

// You can update the cookie
document.cookie = `cookie=triplechoc; expires=${future.toUTCString()}; path=/mouth; HttpOnly`;
console.log(document.cookie); // cookie=triplechoc; expires=Fri, 26 Jan 2017 12:01:00 GMT; path=/mouth; HttpOnly

// Delete the cookie by setting expires to be in the past
document.cookie = `cookie=triplechoc; expires=${past.toUTCString()}; path=/mouth; HttpOnly`;
console.log(document.cookie); // empty