# chai-expected-cookie

> Chai plugin for testing HTTP response set-cookie header and it's also support supertest.

Latest version **1.0.2** (published 2018-01-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-expected-cookie
pnpm add chai-expected-cookie
yarn add chai-expected-cookie
bun add chai-expected-cookie
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-01-01 |
| First published | 2018-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mohamed Saeed |
| Maintainers | msaeed027 |
| Keywords | expected-cookie, chai-expected-cookie, expect, cookie, chai, assertions, expressjs, express |

## Links

- npm: https://www.npmjs.com/package/chai-expected-cookie
- Repository: https://github.com/msaeed027/chai-expected-cookie
- Issues: https://github.com/msaeed027/chai-expected-cookie/issues
- npm.io page: https://npm.io/package/chai-expected-cookie

## Recent versions

- 1.0.2 (latest) — 2018-01-01

## README

# chai-expected-cookie
Chai plugin for testing HTTP response set-cookie header and it's also support supertest.

## Installation
```bash
npm install chai-expected-cookie
```

## Usage
### Quick example
```js
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-http'));
chai.use(require('chai-expected-cookie'));

response = ...

expect(response).to.containCookie({
    name: 'key_1',
});

expect(response).to.not.containCookie({
    name: 'key_2',
});

expect(response).to.containCookie({
    name: 'key_3',
    value: 'vk_3'
});

expect(response).to.containCookie({
    name: 'key_4',
    attrs: {
        path: '/path'
    }
});

expect(response).to.containCookie({
    name: 'key_5',
    hasAttrs: [
        'httponly'
    ]
});

expected(response).to.containCookie({
    name: 'key_6',
    value: 'vk_6',
    attrs: {
        path: '/path'
    },
    hasAttrs: [
        'httponly'
    ]
});
```

### Complete example
```js
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-http'));
chai.use(require('chai-expected-cookie'));

const express = require('express');
const app = express();

chai.request(app)
    .get('/items')
    .end(function(err, response) {         
        expect(response).to.containCookie({
            name: 'key_1',
        });

        expect(response).to.not.containCookie({
            name: 'key_2',
        });

        expect(response).to.containCookie({
            name: 'key_3',
            value: 'vk_3'
        });

        expect(response).to.containCookie({
            name: 'key_4',
            attrs: {
                path: '/path'
            }
        });

        expect(response).to.containCookie({
            name: 'key_5',
            hasAttrs: [
                'httponly'
            ]
        });

        expected(response).to.containCookie({
            name: 'key_6',
            value: 'vk_6',
            attrs: {
                path: '/path'
            },
            hasAttrs: [
                'httponly'
            ]
        });
    });
```
## API
### containCookie(expectedCookie)
assert cookies with defined criteria is set.

*Arguments*

- `expectedCookie` - object represent expected cookie criteria
    - `name` - cookie name
    - `value` - *Optional* cookie value 
    - `attrs` - *Optional* object cookie of attributes
    - `hasAttrs` - *Optional* array of cookie attribute names

## License

MIT

---
_Source: https://npm.io/package/chai-expected-cookie · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
