aliplayer-react icon indicating copy to clipboard operation
aliplayer-react copied to clipboard

Can't initialize test with Jest if a component use aliplayer-react

Open fky2015 opened this issue 4 years ago • 0 comments

When trying to test for component use aliplayer-react, an error triggered in aliplayer-react/lib/index.js indicates that ES6 syntax import used outside the module.

  ● Test suite failed to run

    .../node_modules/aliplayer-react/lib/index.js:12
    import React, { useEffect, useRef, useMemo } from 'react';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import React, { Component } from 'react'
    > 2 | import Player from "aliplayer-react";
        | ^
      3 | import './index.less';
      4 | 
      5 | export default class AliyunPlayer extends Component {

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (src/components/AliyunPlayer/index.jsx:2:1)

I believe that Jest is a Node environment and ES6 syntax is still an experimental feature in Node.

fky2015 avatar Sep 08 '20 15:09 fky2015