Skip to content

ryuuto829/test-node-mongoose-jest

Repository files navigation

test-node-mongoose-jest

A sample project for testing node.js + mongoose app using jest, supertest and mongodb-memory-server.

Read more in this article on dev.to.

⚠️ For the project using old version of mongodb-memory-server (@6.9.3) go to this branch.

Links

Requirements

  • mongodb-memory-server: 7+
  • NodeJS: 12.22+

Usage

  1. Install dependencies:
npm install
  1. Create .env file with mongodb connection string (optional).

  2. Run tests:

npm test

Description

Project structure:

├── models
│   ├── User.js
│   └── Post.js
├── middlewares
│   └── auth.js // Check if user has a token
├── services
│   ├── user.js
│   └── post.js
├── tests
│   ├── db.js
│   ├── auth.test.js
│   └── post.test.js
├── app.js
├── server.js
├── package.json
├── README.md
└── ...

API endpoints:

REQUEST URL Description
POST /api/user/signup register a new user
POST /api/user/login user log in
GET / example of a protected route
POST /api/posts/create create a new post
GET /api/posts/:id get post by id

About

Sample project for testing Node.js + mongoose app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published