【发布时间】:2016-02-19 18:04:12
【问题描述】:
当我import 'electron' 并运行 Jest 时,出现以下错误。使用require 或import 没关系。
jest.autoMockOff() 也无济于事。
FAIL __tests__/root_test.js
● Runtime Error
TypeError: Cannot read property 'on' of undefined
版本如下。
- 节点:v4.2.1
- jest-cli: v0.8.2
- 电子预建:v0.36.4
谁能帮帮我?
【问题讨论】:
-
你是如何运行 JestJS 的?
-
我将
"scripts": {"test": "jest"}写入 package.json 并使用npm test运行。而我的 npm 版本是 2.14.7 -
作为一种解决方法,我将
const remote = require('electron').remote;从文件顶部移到函数中,并且测试通过了。