How should i fix a error on a jest test referencing the cloudinary config

Skye
Skye Member Posts: 1

  TypeError: Cannot read properties of undefined (reading 'config')


     2 | require('dotenv').config();

     3 |

   > 4 | cloudinary.config({

       |           ^

     5 |    cloud_name: process.env.CLOUDINARY_CLOUD_NAME,

     6 |    api_key: process.env.CLOUDINARY_API_KEY,

     7 |    api_secret: process.env.CLOUDINARY_API_SECRET,


     at Object.config (config/cloudinaryConfig.js:4:12)

     at Object.require (controllers/catController.js:2:20)

     at Object.require (__tests__/controlers/createCat.test.js:2:23)

Getting this error when testing my createCat portion of my catController to upload the image with the cat details. Would love some help on how to fix this.

Tagged:

Answers

  • johnr
    johnr Member Posts: 14

    Hi Sky,


    Can you please share your code snippet here? (removing confidential information like API Keys and Secret)

    My best guess is that you failed to require Cloudinary.

    const cloudinary = require('cloudinary').v2;
    

    You also have to make sure to have installed the Cloudinary SDK if you haven't done so yet.


    Best,

    John