{"id":19461678,"url":"https://github.com/plasmapower/assert-request","last_synced_at":"2025-10-14T14:15:01.272Z","repository":{"id":74226372,"uuid":"54927471","full_name":"PlasmaPower/assert-request","owner":"PlasmaPower","description":"Assert responses to HTTP requests in Node.JS","archived":false,"fork":false,"pushed_at":"2016-05-26T22:06:20.000Z","size":15,"stargazers_count":31,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T07:06:44.034Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PlasmaPower.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-28T22:17:54.000Z","updated_at":"2021-06-29T20:18:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c18b590-6886-426f-929e-7f794c847fab","html_url":"https://github.com/PlasmaPower/assert-request","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlasmaPower%2Fassert-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlasmaPower%2Fassert-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlasmaPower%2Fassert-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlasmaPower%2Fassert-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PlasmaPower","download_url":"https://codeload.github.com/PlasmaPower/assert-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223991344,"owners_count":17237476,"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":[],"created_at":"2024-11-10T17:43:19.752Z","updated_at":"2025-10-14T14:14:56.218Z","avatar_url":"https://github.com/PlasmaPower.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assert Request\n\nThis is a tool to assert properties of responses to requests, such as the body, headers, and status code.\nThis returns a promise with additional assertion methods builtin to it.\nIt requires node 4 or higher to run (that's by design, and will not be changed even if you have a PR).\n\n## Example\n\nThis example uses [Mocha](https://mochajs.org/) tests, which natively support promises.\nHowever, `assert-request` is not limited to Mocha.\n\n```js\nlet AssertRequest = require('assert-request');\nlet request = AssertRequest(app.listen()); // You can use a server or protocol and host\n\ndescribe('/example', function () {\n  it('should return HTML', function () {\n    return request('/example')\n      .type('text/html')\n      .okay();\n  });\n});\n\ndescribe('/api', function () {\n  it('should return the correct JSON', function () {\n    return request.post('/api')\n      .type('application/json')\n      .status(200)\n      .json(json =\u003e json.foo \u0026\u0026 json.bar);\n  });\n});\n```\n\n## Return Type\n\nThe returned value is a Promise.\nBecause of that, you can use `.then` and `.catch`.\n`.then` will be passed the response object.\nMany Node.JS utilities such as Mocha will support promises.\n\n## Mixin Documentation\n\nNote: most mixins simply return `this.then(res =\u003e assert(...))`.\nThis means that assertions are guaranteed to run in order.\nWhile technically `Promise.all` should be used here, this makes for a much simpler code base.\nIn addition, this should be the faster way as no mixins created so far return a Promise (i.e. do an asynchronous operation).\n\n### .assert(function)\n\nCalls the function with the response object, and asserts that the return value is truthy.\n\n### .status(expected)\n\nAsserts that the response status is equal to the one specified.\nExpected can be a String, Number, Function, or RegExp.\nStrings and Numbers will be checked without strict matching (`==` not `===`) so the status will be cast to a String.\n\n### .okay()\n\nAsserts that the response status is 200. Equivalent to `.status(200)`\n\n### .header(header, value, someHeaders)\n\nAsserts that the header is present, and if value is specified, asserts that it is equal to the value.\nIn some edge cases like `Set-Cookie`, the header value is an array.\nIn this case, by default all headers must match the value.\nHowever, if someHeaders is true, then only one must match the value.\nValue can be a String, Function, or RegExp.\n\n### .body(expected)\n\nAsserts that the body is equal to the one specified.\nExpected can be a String, Function, or RegExp.\n\n### .json(expected)\n\nAsserts that the body is JSON and is equal to the JSON specified.\nIf expected is a function, then it is passed the parsed JSON.\nExpected can be a String, Function, or RegExp.\n\n\n### .type(expected)\n\nThis is a general mixin to check `Content-Type`.\nIf the expected type is a string, it checkes if any part of the Content-Type is equal.\nAll of the following will match `text/html; charset=utf-8`\n\n- 'text/html; charset=utf-8'\n- 'text/html'\n- 'charset=utf-8'\n- /html/\n- /^text\\/html; charset=utf-8$/\n- type =\u003e type.includes('html')\n\nThe following will NOT match that type:\n\n- /^text\\/html$/\n- type =\u003e type === 'text/html'\n\nExpected can be a String, Function, or RegExp.\nHowever, partial matching is only applied to strings as specified above.\n\n## Inspiration\n\nThis was made as a replacement for [supertest](https://github.com/visionmedia/supertest).\nInspiration was taken from that API.\nHowever, using it also showed how it could be improved, and pitfalls to avoid.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplasmapower%2Fassert-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplasmapower%2Fassert-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplasmapower%2Fassert-request/lists"}