Reputation: 2980
While testing the application with Jest I'm getting an Type Error : Cannot read property 'user_env_variable is undefined
error.
because of 'user_env_variable is undefined'
error I have modified if else check
if(config.user_env_variable) {...} else {...}
to
if(config.user_env_variable!== undefined) {...} else {...}
but still I am getting the same error.
This is how my dbconfig.json will look like
dbconfig.json
{
"development": {
"username": "dev",
"password": "******",
"database": "userdb",
"host": "user-management-dev-xxxx",
"port": "5432",
"dialect": "postgres"
}
}
Any kind of help is much appreciated.
Upvotes: 0
Views: 643
Reputation: 71
use This:
if(typeof(config.user_env_variable==="undefined"))
or use typeof undefined this is gonna solve your problem
Upvotes: 0
Reputation: 430
Try typeof
operator. Something like this. Check undefined
is string not keyword.
if(typeof config !== "undefined" && typeof config.user_env_variable!== "undefined") {...} else {...}
Upvotes: 1