plougsgaard / react-timeout

Component wrapper for setTimeout et al that cleans up after itself.
127 stars 17 forks source link

TypeError: react_timeout_1.default is not a function #19

Closed ashwinsaval closed 5 years ago

ashwinsaval commented 7 years ago

Hi, My Jest test cases are failing with the following error:

 TypeError: react_timeout_1.default is not a function

The test case is a simple render and check if the component is loading fine. Any reason why I am facing this error while testing?

ashwinsaval commented 7 years ago

@plougsgaard need some help here.

ashwinsaval commented 7 years ago

Okay I seem to have found the issue but it still needs a resolution, since I currently have to hack the usage of react-timeout to make it work in my tests. Surprisingly, react-timeout works fine in dev environment but not in tests. Here are my observations:

Setup

Typescript + Jest + Enzyme

Usage:

import ReactTimeout from 'react-timeout';

class MyClass {
...
}

export default ReactTimeout(MyClass)

The error

When using in dev environment, everything works fine. However, when attempting to run a simple test with my component, I get the following error:

TypeError: react_timeout_1.default is not a function

Looking at Issue https://github.com/Microsoft/TypeScript/issues/3019, it looks like the issue is with a missing .d.ts typescript definition file in the project.

Current Fix

We are currently working around this issue by using all imports in the following way, however it is not the final solution:

const ReactTimeout = require('react-timeout');

I would love to hear of the proper resolution of this issue and what can be done.

plougsgaard commented 7 years ago

@ashwinsaval

I've just been on holiday so didn't see your issue until now.

Looking at the issue you reference it seems like TypeScript needs the definition files from somewhere, and I'd be happy to add them to this project if it means greater compatibility.

If you're familiar with how to write them you could see if putting a .d.ts inside node_modules/react-timeout fixes your problem. As I don't have a reproducible test case that fails it would probably take me a while. 😄

Thanks for bringing this to attention!

afilp commented 6 years ago

Is this just a DEV issue? Are we OK with production? I am worried whether things will break in production. Thanks!