Skip to content

[BUG] Cannot be imported in Jest with Next.js #240

@xian0831

Description

@xian0831

Describe the bug

@asmyshlyaev177 Thanks for building this library. I would like to report an issue I'm facing related to testing components that leverage the react-horizontal-scrolling-menu. I'm able to build the app fine, it is just not working with Jest unit test.

To Reproduce
There is not issue when using the library so there is nothing to reproduce.

I suspect the issue might have something to do with the Jest transform.This is the config I have.

    // A map from regular expressions to paths to transformers
    transform: {
        '^.+\\.(t|j)sx?$': [
            'babel-jest',
            {
                presets: ['next/babel'],
                plugins: [
                    'dynamic-import-node',
                    [
                        'babel-plugin-styled-components',
                        {
                            displayName: true,
                            preprocess: false,
                            fileName: false,
                        },
                    ],
                ],
            },
        ],
        '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2|svg)$':
            'jest-transform-stub',
    },

When I run the test, this is what I get SyntaxError: Cannot use import statement outside a module

image

Expected behavior
Successfully rendering by Jest using jsdom

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Package Version: 4.1.0
  • Platform: Next.js 12.1.0
  • Assertion Lib: Jest + React Testing Library

Additional context
Someone else had anther import issue. I suspect it is somewhat related to this issue. However, I can't confirm that. Again, thanks for building the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions