h is not defined error while running test cases in preact

Viewed 205

I have a preact application which uses @testing-library/preact library for test cases. When I try to run a test for a component it throws an error stating that h is not defined. The app works without the import statement in the components but the test cases doesn't work. I get the it is required for converting jsx to h() calls. But is there any way to avoid it so that I don't have to import it in every component in the app ? PS: I tried to configure babel with this plugic babel-plugin-jsx-pragmatic for automatic import but it didn't work. This is my .babelrc file.

{
   "plugins": [
        ["plugin-transform-react-jsx", {
            "runtime": "automatic",
            "importSource": "preact"
        }]
    ]
}
0 Answers
Related