Rajath
Rajath

Reputation: 2980

Jest is throwing error > Type Error : Cannot read property 'user_env_variable is undifined

While testing the application with Jest I'm getting an Type Error : Cannot read property 'user_env_variable is undefined error.

enter image description here

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

Answers (2)

cemil
cemil

Reputation: 71

use This:

if(typeof(config.user_env_variable==="undefined"))

or use typeof undefined this is gonna solve your problem

Upvotes: 0

Sagar
Sagar

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

Related Questions