0

How to predict _id in jest test using mockingoose

const newUser = new User({
    username: username,
    name,
    email: email,
    password: password,
})

how to know what id will new User() return

const user = {
    id: 'a'
    username: 'username',
    name: 'Name',
    email: 'email@example.com',
    password: 'password',
}

User schema

import mongoose, { Schema } from 'mongoose'

const User = new Schema(
    {
        username: { type: String, required: true },
        name: { type: String, required: true },
        email: { type: String, required: true },
        password: { type: String, required: true },
    },
    { timestamps: true }
)

how to make user same as newUser

kennarddh
  • 2,186
  • 2
  • 6
  • 21

0 Answers0