Does Jest support ES6 import/export?

后端 未结 7 854
情话喂你
情话喂你 2020-11-29 01:21

If I use import/export from ES6 then all my Jest tests fail with error:

Unexpected reserved word

I convert my object un

7条回答
  •  生来不讨喜
    2020-11-29 01:32

    I encountered the same issue.

    These are what I did:

    yarn add --dev babel-jest @babel/core @babel/preset-env

    Make file jest.config.js in rootDir.

    module.exports = {
        moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "json"],
        transform: {
            '^.+\\.(js|jsx)?$': 'babel-jest'
        },
        testEnvironment: 'node',
        moduleNameMapper: {
            '^@/(.*)$': '/$1'
        },
        testMatch: [
            '/**/*.test.(js|jsx|ts|tsx)', '/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))'
        ],
        transformIgnorePatterns: ['/node_modules/']
    };
    

    Then make file babal.config.js in rootDir.

    Go like this:

    module.exports = {
        "presets": ["@babel/preset-env"]
    }
    

提交回复
热议问题