Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error thrown within Jest unit test #100

Open
epfromer opened this issue Aug 24, 2020 · 1 comment
Open

error thrown within Jest unit test #100

epfromer opened this issue Aug 24, 2020 · 1 comment

Comments

@epfromer
Copy link

I have a Jest unit test throwing an error when testing the creation of a bar chart. The call stack is as follows:

  console.error
    Failed to fetch scripts or layout. Cannot read property 'includes' of undefined
      at CustomConsole.Object.<anonymous>.console.error (../../node_modules/react-native/Libraries/LogBox/LogBox.js:33:14)
      at registerError (../../node_modules/react-native/Libraries/YellowBox/YellowBox.js:169:7)
      at errorImpl (../../node_modules/react-native/Libraries/YellowBox/YellowBox.js:84:22)
      at CustomConsole.error (../../node_modules/react-native/Libraries/YellowBox/YellowBox.js:63:14)
      at _callee$ (../../node_modules/@highcharts/highcharts-react-native/src/HighchartsReactNative.js:47:21)
      at tryCatch (../../node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (../../node_modules/regenerator-runtime/runtime.js:293:22)

I have traced it in the HighchartsReactNative.js file to setHcAssets(), calling this.setLayout(), calling this.getAssetAsString() and the following code:

        const downloadedModules = await FileSystem.readDirectoryAsync(FileSystem.cacheDirectory)
        let fileName = 'ExponentAsset-' + asset.hash + '.' + asset.type
        if (!downloadedModules.includes(fileName)) {
            await asset.downloadAsync()
        }

Seems like FileSystem react-native-unimodules is mocked, and has no cacheDirectory?

I tried the following

if (downloadedModules && !downloadedModules.includes(fileName)) {

But am now getting:

console.error
    Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.   
        in HighchartsReactNative (created by BarHighcharts)

For the unit test, I'm using @testing-library/react-native.

Anyway, I thought you should know. If this is an error on my part, please advise.

@Denyllon
Copy link
Contributor

Denyllon commented Aug 25, 2020

Hi @epfromer ,

Thank you for your report.
This package has no test implementation yet, and we've never run it combined with Jest before. Basically, it could be quite hard to find out what can be the general reason of these kind of problems.

Seems like FileSystem react-native-unimodules is mocked, and has no cacheDirectory?

The biggest problem is that I'm not able to find any information about using the mentioned package with Jest, and we do not know how it should be configured to access cacheDirectory. I think would be better to ask about that on their repository.

One thing which comes to my mind for now it to set useCDN flag to true and let the wrapper fetch all required Highcharts scripts from the outside. Have you tried it?

Kind regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants