Node v13 / Jest / ES6 — native support for modules without babel or esm

前端 未结 4 1415
心在旅途
心在旅途 2020-12-11 00:47

Is it possible to test ES6 Modules with Jest without esm or babel? Since node v13 supports es6 natively have tried:

//         


        
4条回答
  •  萌比男神i
    2020-12-11 01:25

    I followed the tips provided in the accepted answer, but I added the property "type": "module" in my package.json in order to jest works properly. This is what I done:

    In package.json:

    "devDependencies": {
        "jest": "^26.1.0",
        "jest-environment-jsdom-sixteen": "^1.0.3",
        "jest-environment-node": "^26.1.0"
      },
      "scripts": {
        "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
      },
      "type": "module",
      "jest": {
        "transform": {},
        "testEnvironment": "jest-environment-jsdom-sixteen"
      }
    

提交回复
热议问题