TOOL: mongodb-memory-server
const productSchema = new mongoose.Schema({
name: { type: String, required: true},
price: { type: Number, required: true},
description: {type: String},
});
<export>
<import productModel>
module.exports.create = async (product) => {
if (!product)
throw new Error('Missing product');
await productModel.create(product);
}
"scripts": {
"test": "jest --runInBand ./test"
}
"jest": {
"testEnvironment": "node"
}