{"id":28076683,"url":"https://github.com/jaredhanson/chai-connect-middleware","last_synced_at":"2025-05-13T01:45:41.041Z","repository":{"id":57196540,"uuid":"12410447","full_name":"jaredhanson/chai-connect-middleware","owner":"jaredhanson","description":"Helpers for testing Connect middleware with the Chai assertion library.","archived":false,"fork":false,"pushed_at":"2018-01-04T16:32:00.000Z","size":26,"stargazers_count":8,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T01:45:32.621Z","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/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-27T15:51:35.000Z","updated_at":"2019-07-11T15:52:15.000Z","dependencies_parsed_at":"2022-09-15T15:41:06.180Z","dependency_job_id":null,"html_url":"https://github.com/jaredhanson/chai-connect-middleware","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fchai-connect-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fchai-connect-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fchai-connect-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fchai-connect-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/chai-connect-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856614,"owners_count":21974575,"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":"2025-05-13T01:45:36.123Z","updated_at":"2025-05-13T01:45:41.035Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-connect-middleware\n\n[![Version](https://img.shields.io/npm/v/chai-connect-middleware.svg?label=version)](https://www.npmjs.com/package/chai-connect-middleware)\n[![Build](https://img.shields.io/travis/jaredhanson/chai-connect-middleware.svg)](https://travis-ci.org/jaredhanson/chai-connect-middleware)\n[![Quality](https://img.shields.io/codeclimate/github/jaredhanson/chai-connect-middleware.svg?label=quality)](https://codeclimate.com/github/jaredhanson/chai-connect-middleware)\n[![Coverage](https://img.shields.io/coveralls/jaredhanson/chai-connect-middleware.svg)](https://coveralls.io/r/jaredhanson/chai-connect-middleware)\n[![Dependencies](https://img.shields.io/david/jaredhanson/chai-connect-middleware.svg)](https://david-dm.org/jaredhanson/chai-connect-middleware)\n\n\nHelpers for testing [Connect](http://www.senchalabs.org/connect/) middleware\nwith the [Chai](http://chaijs.com/) assertion library.\n\n## Install\n\n    $ npm install chai-connect-middleware\n\n## Usage\n\n#### Use Plugin\n\nUse this plugin as you would all other Chai plugins:\n\n```javascript\nvar chai = require('chai');\n\nchai.use(require('chai-connect-middleware'));\n```\n\n#### Implement Test Cases\n\nOnce used, the `chai.connect.use` helper function will be available to set up\ntest cases for Connect middleware.\n\nThe helper function can be called from a hook to setup the test case.  The\nhelper returns a wrapper on which callbacks are registered to be executed\nwhen the middleware invokes `next` or `end`s the response.  If the middleware\nfinishes in an unexpected way, the test helper will automatically throw an\nexception.\n\nThe following demonstrates a [Mocha](http://mochajs.org/) test\ncase.\n\n```javascript\ndescribe('middleware test', function() {\n  var res;\n    \n  before(function(done) {\n    chai.connect.use(middleware)\n      .req(function(req) {\n        req.query = { hello: 'Bob' };\n      })\n      .end(function(r) {\n        res = r;\n        done();\n      })\n      .dispatch();\n  });\n\n  it('should send correct body', function() {\n    expect(res.body).to.equal('Hello, Bob');\n  });\n});\n```\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2013-2017 Jared Hanson \u003c[http://jaredhanson.net/](http://jaredhanson.net/)\u003e\n\n\u003ca target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/vK9dyjRnnWsMzzJTQ57fRJpH/jaredhanson/chai-connect-middleware'\u003e\n  \u003cimg alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/vK9dyjRnnWsMzzJTQ57fRJpH/jaredhanson/chai-connect-middleware.svg' /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fchai-connect-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fchai-connect-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fchai-connect-middleware/lists"}