{"id":14989753,"url":"https://github.com/marcl/js-unit-testing-examples","last_synced_at":"2025-04-12T00:32:07.376Z","repository":{"id":71372434,"uuid":"83140738","full_name":"MarcL/js-unit-testing-examples","owner":"MarcL","description":"🤓 JavaScript Unit Testing Examples","archived":false,"fork":false,"pushed_at":"2023-03-14T10:49:15.000Z","size":22,"stargazers_count":20,"open_issues_count":1,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T20:51:13.426Z","etag":null,"topics":["chai","express","javascript","middleware","mocha","promises","sinon","unit-testing"],"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":"2017-02-25T15:25:11.000Z","updated_at":"2023-08-05T21:49:58.000Z","dependencies_parsed_at":"2024-09-25T00:34:37.352Z","dependency_job_id":null,"html_url":"https://github.com/MarcL/js-unit-testing-examples","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.04347826086956519,"last_synced_commit":"5718c7a96f54d51710be20b064c98cc913c3ae8f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fjs-unit-testing-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fjs-unit-testing-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fjs-unit-testing-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fjs-unit-testing-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcL","download_url":"https://codeload.github.com/MarcL/js-unit-testing-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501410,"owners_count":21114674,"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":["chai","express","javascript","middleware","mocha","promises","sinon","unit-testing"],"created_at":"2024-09-24T14:18:52.079Z","updated_at":"2025-04-12T00:32:07.108Z","avatar_url":"https://github.com/MarcL.png","language":"JavaScript","readme":"# JavaScript Unit Testing Examples\n\nExample project to allow me to show how best to unit test a JavaScript Express application.\n\n## Install\n\nClone this repository and install the dependencies as follows:\n\n```\ngit clone git@github.com:MarcL/js-unit-testing-framework.git\nnpm install\n```\n\n## Running the tests\n\nThe code sets up a basic Express server with a few routes and some tests which cover testing the server setup. Run the test suite using npm:\n\n```\nnpm test\n```\n\n## JavaScript Tests\n\nTake a look in the `test` directory to see all of the test code. There are lots of examples of different types of tests and how to create them.\n\n### Asynchronous functions and promises\n\nSome examples of how to test asynchronous functions and promises, including some tips and tricks and gotchas.\n\n#### Asynchronous function\n- Timeout because `done` callback isn't called when function succeeds\n- Passing test but slow because timer isn't stubbed\n- Passing test and fast because timer is stubbed\n- Timeout because `done` callback isn't called when function throws an error\n- Passing test to call `done` callback when function throws an error\n\n#### Promise : resolving\n- Test passes incorrectly because Promise isn't returned\n- Passing test because promise is returned\n- Passing test because `done` callback is called after resolution\n- Passing test because `done` callback is called after resolution using `chai-as-promised` syntax\n\n#### Promise : rejecting\n- Test passes incorrectly because Promise isn't returned\n- Failing test because rejected Promise error isn't caught\n- Passing test because Promise is returned and rejection is caught\n- Passing test because Promise rejection is caught and `done` callback is called\n- Passing test because Promise rejection is caught and `done` callback is called using `chai-as-promised` syntax\n\n#### Slow tests\n- Passing test but is slow due to Promise function in chain taking a long time\n- Passing test and much faster as longer function is now stubbed to execute immediately\n\n## License\n\nSee [LICENSE](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Fjs-unit-testing-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcl%2Fjs-unit-testing-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Fjs-unit-testing-examples/lists"}