ec.cookie-mock

    1.0.1 • Public • Published

    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

    Keywords

    none

    Install

    npm i ec.cookie-mock

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    ISC

    Last publish

    Collaborators

    • scherzinger
    • deyhle
    • ehlerskon