{"id":16979344,"url":"https://github.com/marcl/unit-test-express-routes","last_synced_at":"2026-02-05T09:34:15.211Z","repository":{"id":71372486,"uuid":"73018931","full_name":"MarcL/unit-test-express-routes","owner":"MarcL","description":"Example of how to unit test Express routes","archived":false,"fork":false,"pushed_at":"2016-11-15T00:01:52.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-29T15:11:34.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/MarcL.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-11-06T21:05:33.000Z","updated_at":"2022-07-17T18:16:04.000Z","dependencies_parsed_at":"2023-03-11T10:25:33.731Z","dependency_job_id":null,"html_url":"https://github.com/MarcL/unit-test-express-routes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MarcL/unit-test-express-routes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Funit-test-express-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Funit-test-express-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Funit-test-express-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Funit-test-express-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcL","download_url":"https://codeload.github.com/MarcL/unit-test-express-routes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Funit-test-express-routes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29118445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T05:31:32.482Z","status":"ssl_error","status_checked_at":"2026-02-05T05:31:29.075Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-14T01:45:32.095Z","updated_at":"2026-02-05T09:34:15.189Z","avatar_url":"https://github.com/MarcL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unit Testing Express Routes\n\nExample project to show how to unit test Express routes using [Mocha](https://mochajs.org/), [Sinon](http://sinonjs.org/), [Chai](http://chaijs.com/) and [Proxyquire](https://github.com/thlorenz/proxyquire).\n\n## Install\n\nClone this repository and install the dependencies as follows:\n\n```\ngit clone git@github.com:MarcL/unit-test-express-routes.git\nnpm install\n```\n\n## Running the tests\n\nThe code sets up a basic Express server with a few routes and szome tests which just cover testing the server setup. The middlewares have no tests as they're simply there for stubbing expectations in the `launch.test.js` tests. Run the test suite using npm:\n\n```\nnpm test\n```\n\nThe tests assert that the routes are set up with the expected middleware. In my mind, it helps to complete code coverage, and also helps to guarantee that the routes are called with all of the expected middleware. A good example is for routes that are locked down using an authentication layer. Your tests can now assert that the authentication middleware is **definitely** called on the the expected routes. In this case it means that these test almost become and additional set of security tests too.\n\nI'd expect there to be an additional layer of integration testing using [supertest](https://github.com/visionmedia/supertest) and [nock](https://github.com/node-nock/nock) which would better verify the full flow on each route too.\n\nI've written a blog post about the reasoning behind why and how you would unit test Express routes here:\n\n[How To Unit Test Express Routes](http://www.marclittlemore.com/how-to-unit-test-express-routes/?utm_source=github\u0026utm_campaign=unit-test-express-routes\u0026utm_medium=repository) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Funit-test-express-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcl%2Funit-test-express-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Funit-test-express-routes/lists"}