1

I am using owl.carousel package in my application and testing it using jest my file is running fine but when i run the test case i get the following error

my code file › encountered a declaration exception enter image description here

test case error on require file

 fit("save button functionality",async ()=>{
             let { addDevice } = require('./codeFile')
            // $.fn.owlCarousel = jest.fn().mockImplementation(()=>{
               //  console.log('using my owl carousel');
            // })
            let addDeviceButton = document.getElementsByClassName("button-link")[0];
    
            await addDevice(addAnotherDeviceButton);
    
        })

getting error on require of code file

package.json

{
    "@testing-library/dom": "^6.11.0",
    "@testing-library/jest-dom": "^5.16.5",
    "jest": "^25.0.0",
    "owl.carousel": "^2.3.4",
    "jest-environment-jsdom": "^25.0.0",
    "jest": {
       "testEnvironment": "jsdom",
       "coverageThreshold": {
          "global": {
             "branches": 50,
             "functions": 50,
             "lines": 50,
             "statements": 50
        }
    },
    "transform": {
      "^.+\\.js$": "babel-jest",
      ".+\\.(css|scss|png|jpg|svg)$": "jest-transform-stub"
    }
  }
}

I understand from my analysis that owlCarousel is a prototype function being added on jquery and in the code $.fn.owlCarousel it is saying $ is undefined

but why is that happening ?

ash1102
  • 409
  • 4
  • 20
  • Hi, I am facing the same issue, did you find the solution https://stackoverflow.com/questions/76794852/reactjs-jest-testing-issue-with-react-owl-carousel – Ravi Kumar Aug 02 '23 at 19:12

0 Answers0