{"id":19245700,"url":"https://github.com/henryckh/node-tdd-example","last_synced_at":"2026-05-10T03:16:11.194Z","repository":{"id":44221321,"uuid":"135376095","full_name":"henryckh/node-tdd-example","owner":"henryckh","description":"Nodejs with test driven development.","archived":false,"fork":false,"pushed_at":"2023-01-11T00:56:14.000Z","size":295,"stargazers_count":2,"open_issues_count":10,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-02T15:45:12.987Z","etag":null,"topics":["chai","mocha","node-tdd"],"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/henryckh.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":"2018-05-30T02:17:57.000Z","updated_at":"2023-03-04T05:00:47.000Z","dependencies_parsed_at":"2023-02-08T21:01:51.210Z","dependency_job_id":null,"html_url":"https://github.com/henryckh/node-tdd-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/henryckh/node-tdd-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryckh%2Fnode-tdd-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryckh%2Fnode-tdd-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryckh%2Fnode-tdd-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryckh%2Fnode-tdd-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henryckh","download_url":"https://codeload.github.com/henryckh/node-tdd-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryckh%2Fnode-tdd-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266057197,"owners_count":23870122,"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","mocha","node-tdd"],"created_at":"2024-11-09T17:29:08.051Z","updated_at":"2026-05-10T03:16:11.145Z","avatar_url":"https://github.com/henryckh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-tdd-example\nProject example using Mocha, chai to do test driven development for Node.js. \n\n## Prerequisites\nInstall Mocha globally by running:\n```sh\n$ npm install -g mocha\n```\n\nInstall mongodb and run at port 27017\n\nDuring filling npm init, input mocha for \"test command\", \nYour package.json file should contain the following field:\n```js\n\"script\": {\n    \"test\": \"mocha\"\n}\n````\n\n## Test http request\nUse supertest to test api from express\n```js\ndescribe('Feed API', () =\u003e {\n    describe('Get Image list', () =\u003e {\n        it('should return images of link in array', (done) =\u003e {\n            api.get('/images')\n                .expect(200)\n                .end((err, res) =\u003e {\n                    if (err) done(err);\n\n                    expect(res.body).to.have.property('images');\n                    expect(res.body.images).to.be.an('array');\n                    done();\n                });\n        })\n    });\n});\n```\n\n## Test function execution\nTest logging with sandbox\n```js\ndescribe('Sanbox Winston Log', () =\u003e {\n    describe('Log an info level message in sandbox', () =\u003e {\n\n        beforeEach(() =\u003e {\n            this.sandbox = sinon.createSandbox();\n        });\n        it('should logged \"hello world\"', () =\u003e {\n            sinon.stub(logger, 'info');\n            logger.info('hello world');\n            expect(logger.info).to.have.been.calledWith('hello world');\n        });\n        afterEach(() =\u003e {\n            this.sandbox.restore()\n        });\n    })\n});\n```\n\n## Test writing to Database\n```js\ndescribe('User Controller', () =\u003e {\n    describe('Create a new user', () =\u003e {\n\n        before(() =\u003e {\n            db.connect(()=\u003e {\n            });\n        });\n\n        it('should return saved document with property \"name\"', () =\u003e {\n            let tom = new User({\n                name: \"Tom\"\n            });\n            return expect(userController.create(tom)).to.eventually.has.property('name');\n        });\n    })\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryckh%2Fnode-tdd-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryckh%2Fnode-tdd-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryckh%2Fnode-tdd-example/lists"}