Jest fails with “Unexpected token *” on import statement

前端 未结 5 600
南旧
南旧 2021-02-03 18:15

Why does Jest fail with \"Unexpected token *\" on a simple import statement...

Error log:

Admin@Admin-PC MINGW32 /d/project (master)
$ npm         


        
5条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 18:25

    I am using react-native-web and the fix for my issue was to add the react-native-web preset to my jest.config.js:

    module.exports = {
    transform: {
      '^.+\\.tsx?$': 'ts-jest',
    },
    timers: 'fake',
    testPathIgnorePatterns: [
      '/build/',
      '/node_modules/',
      '/rndemo/build/',
    ],
    globals: {
      'ts-jest': {
        diagnostics: {
          warnOnly: true,
        },
      },
    },
    preset: 'react-native-web',
    }
    

提交回复
热议问题