Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Babel使用Webpack进行编译,但不使用玩笑_Node.js_Webpack_Babeljs_Jestjs_Es6 Class - Fatal编程技术网

Node.js Babel使用Webpack进行编译,但不使用玩笑

Node.js Babel使用Webpack进行编译,但不使用玩笑,node.js,webpack,babeljs,jestjs,es6-class,Node.js,Webpack,Babeljs,Jestjs,Es6 Class,我正在尝试使用Babel withenvpreset设置Jest来处理我的ES6项目。代码可以编译并使用Webpack,但不能使用Jest。问题似乎是从节点\u模块内部传输代码 package.json(纱线): toolbox.js中的定义: import EventPubSub from 'event-pubsub' class GUI { gui config values constructor() { // some valid code } } c

我正在尝试使用Babel with
env
preset设置Jest来处理我的ES6项目。代码可以编译并使用Webpack,但不能使用Jest。问题似乎是从
节点\u模块内部传输代码

package.json(纱线):

toolbox.js中的定义:

import EventPubSub from 'event-pubsub'

class GUI {
  gui
  config
  values

  constructor() {
    // some valid code
  }
}


class MIDI extends EventPubSub {
  midi

  constructor() {
    super()

    // some valid code down there
  }
}
test.js:

import {GUI, MIDI} from './toolbox.js'

test('gui sanity', () => { // <--- pass
  let gui = new GUI()
  expect(gui).toBeTruthy()
});

test('midi sanity', () => { // <--- fail
  let midi = new MIDI()
  expect(midi).toBeTruthy()
});
从“/toolbox.js”导入{GUI,MIDI}
test('gui健全性',()=>{/{//101 |构造函数(){
102 | super()
103 | 
104 |//请求MIDI访问
在新的MIDI上(toolbox.js:101:17)
at对象。(test.js:15:14)

所以,因为我想从
node_modules
中扩展ES6类,所以我必须在jest配置中明确排除它:

  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/(?!event-pubsub).+\\.js$"
    ]
  }
这样,模块将按原样导入到我的测试中(不传输)

import {GUI, MIDI} from './toolbox.js'

test('gui sanity', () => { // <--- pass
  let gui = new GUI()
  expect(gui).toBeTruthy()
});

test('midi sanity', () => { // <--- fail
  let midi = new MIDI()
  expect(midi).toBeTruthy()
});
TypeError: Class constructor EventPubSub cannot be invoked without 'new'

   99 |   midi
  100 | 
> 101 |   constructor() {
  102 |     super()
  103 | 
  104 |     // request MIDI access

  at new MIDI (toolbox.js:101:17)
  at Object.<anonymous> (test.js:15:14)
  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/(?!event-pubsub).+\\.js$"
    ]
  }