Stack Exchange
validated variable is present and datatype assertion using Jest testing
I have 2 files as below
admin.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const Schema = new Schema({
    User: { type: String, unique: true },
    Pass: { type: String },
});

var Admin = mongoose.model("admin", Schema);
module.exports = Admin;

admin.test.js
const Admin = require('./admin.js');

test("verify username is present and datatype is correct", () => {
 if (typeof Admin.Admin !== "undefined") {
        // this statement will not execute
        console.log('username is DEFINED');
    } else {
        console.log('username is not DEFINED');
    }

});

I need to validate that the Username is present and validate datatype is a string. I am not able to call the Username from another file.

Your admin.js is :
const mongoose = require("mongoose");
let Schema = mongoose.Schema;
Schema = new Schema({
    User: { type: String, unique: true },
    Pass: { type: String },
});

var Admin = mongoose.model("admin", Schema);
module.exports = Admin;

here you are exporting the identifier "Admin" . So when you import admin.js using require in any other module "Admin" will be exposed .
const Admin = require('./admin.js');

console.log(Admin)

You don't have to call Admin.Admin , it will return undefined always as "Admin" variable has a model and doesn't have any property called "Admin"

is there a way that I can test the datatype defined as expected for the unit test?
