{"id":26715529,"url":"https://github.com/gregl83/expect-cookies","last_synced_at":"2025-07-29T19:39:58.023Z","repository":{"id":53075901,"uuid":"46190605","full_name":"gregl83/expect-cookies","owner":"gregl83","description":"SuperTest Cookie Assertions","archived":false,"fork":false,"pushed_at":"2021-04-07T21:41:39.000Z","size":38,"stargazers_count":11,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:26:15.238Z","etag":null,"topics":["cookies","nodejs","supertest","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gregl83.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-14T20:19:59.000Z","updated_at":"2025-03-19T02:01:10.000Z","dependencies_parsed_at":"2022-09-10T04:32:59.362Z","dependency_job_id":null,"html_url":"https://github.com/gregl83/expect-cookies","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fexpect-cookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fexpect-cookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fexpect-cookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fexpect-cookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregl83","download_url":"https://codeload.github.com/gregl83/expect-cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248800077,"owners_count":21163404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cookies","nodejs","supertest","testing"],"created_at":"2025-03-27T14:25:37.129Z","updated_at":"2025-07-29T19:39:57.997Z","avatar_url":"https://github.com/gregl83.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/gregl83/expect-cookies/actions/workflows/build.yml/badge.svg)](https://github.com/gregl83/expect-cookies/actions/workflows/build.yml)\n[![Coverage Status](https://codecov.io/gh/gregl83/expect-cookies/graph/badge.svg?token=S9vGTwnOw6)](https://codecov.io/gh/gregl83/expect-cookies)\n[![NPMjs.com](https://img.shields.io/npm/v/expect-cookies.svg)](https://www.npmjs.com/package/expect-cookies)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/gregl83/expect-cookies/blob/master/LICENSE)\n# expect-cookies\n\nSuperTest Cookie Assertions\n\nHTTP cookie assertions via [super-test](https://github.com/visionmedia/supertest).\n\nWriting HTTP cookie tests can result in redundant and verbose test code.\n\nThis module was written to make testing cookies easier and reduce redundancies.\n\n## Requirements\n\n- NodeJS v0.12.x or higher\n- NPM\n- SuperTest for HTTP testing\n\nSee `./package.json`\n\n## Installation\n\nSource available on [GitHub](https://github.com/gregl83/expect-cookies) or install module via NPM:\n\n    $ npm install expect-cookies\n\n## Usage\n\nUsage instructions assume general knowledge of [super-test](https://github.com/visionmedia/supertest).\n\nHere is an example of using the `set` and `not` cookie assertions:\n\n```js\n// get ExpectCookies module\nconst Cookies = require('expect-cookies');\n\n// setup super-test\nconst request = require('supertest');\nconst express = require('express');\n\n// setup express test service\nconst app = express();\n\napp.get('/users', function(req, res){\n  res.cookie('alpha', 'one', {domain: 'domain.com', path: '/', httpOnly: true});\n  res.send(200, { name: 'tobi' });\n});\n\n// test request to service\nrequest(app)\n  .get('/users')\n  .expect('Content-Type', /json/)\n  .expect('Content-Length', '20')\n  .expect(200)\n  // assert 'alpha' cookie is set with domain, path, and httpOnly options\n  .expect(Cookies.set({'name': 'alpha', 'options': ['domain', 'path', 'httponly']}))\n  // assert 'bravo' cookie is NOT set\n  .expect(Cookies.not('set', {'name': 'bravo'})\n  .end(function(err, res){\n    if (err) throw err;\n  });\n```\n\nIt is also possible to chain assertions:\n\n```js\nCookies.set({/* ... */}).not('set', {/* ... */})\n```\n\n## API\n\nFunctions and methods are chainable.\n\n### Cookies([secret], [asserts])\n\nGet assertion function for [super-test](https://github.com/visionmedia/supertest) `.expect()` method.\n\n*Arguments*\n\n- `secret` - String or array of strings. Cookie signature secrets.\n- `asserts(req, res)` - Function or array of functions. Failed custom assertions should throw. \n\n### .set(expects, [assert])\n\nAssert that cookie and options are set.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `options` - *Optional* array of options.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n### .reset(expects, [assert])\n\nAssert that cookie is set and was already set (in request headers).\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n### .new(expects, [assert])\n\nAssert that cookie is set and was NOT already set (NOT in request headers).\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n### .renew(expects, [assert])\n\nAssert that cookie is set with a strictly greater `expires` or `max-age` than the given value.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `options` - Object of options. `use one of two options below`\n   - `options`.`expires` - String UTC expiration for original cookie (in request headers).\n   - `options`.`max-age` - Integer ttl in seconds for original cookie (in request headers).\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n### .contain(expects, [assert])\n\nAssert that cookie is set with value and contains options.\n\nRequires `Cookies(secret)` initialization if cookie is signed.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `value` - *Optional* string unsigned value of cookie.\n  - `options` - *Optional* object of options.\n   - `options`.`domain` - *Optional* string domain.\n   - `options`.`path` - *Optional* string path.\n   - `options`.`expires` - *Optional* string UTC expiration.\n   - `options`.`max-age` - *Optional* integer ttl, in seconds.\n   - `options`.`secure` - *Optional* boolean secure flag.\n   - `options`.`httponly` - *Optional* boolean httpOnly flag.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n### .not(method, expects)\n\nCall any cookies assertion method with \"assert true\" modifier set to `false`.\n\nSyntactic sugar.\n\n*Arguments*\n\n- `method` - String method name. Arguments of method name apply in `expects`.\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `value` - *Optional* string unsigned value of cookie.\n  - `options` - *Optional* object of options.\n\nThat's it!\n\n## License\n\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregl83%2Fexpect-cookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregl83%2Fexpect-cookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregl83%2Fexpect-cookies/lists"}