错误测试会对包含react-toolbox组件的组件做出反应

时间:2017-03-06 09:06:42

标签: reactjs mocha chai enzyme react-toolbox

我正在尝试测试一些包含来自react工具箱的组件的反应组件,当我在测试文件中导入它们时,我收到此错误:

C:\project\landscapp\App\node_modules\react-toolbox\lib\ripple\theme.scss:1
(function (exports, require, module, __filename, __dirname) { @import "../colors";
                                                              ^
SyntaxError: Invalid or unexpected token
at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\project\landscapp\App\node_modules\react-toolbox\lib\ripple\index.js:13:14)
    at Module._compile (module.js:570:32)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\project\landscapp\App\node_modules\react-toolbox\lib\button\index.js:22:15)
    at Module._compile (module.js:570:32)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\project\landscapp\App\node_modules\react-toolbox\lib\index.js:8:15)
    at Module._compile (module.js:570:32)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:/project/landscapp/App/src/modules/Core/input/labeledInput.js:2:1)
    at Module._compile (module.js:570:32)
    at loader (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\project\landscapp\App\src\modules\Core\input\index.js:8:21)
    at Module._compile (module.js:570:32)
    at loader (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:/project/landscapp/App/src/modules/Users/UserCard/components/accountSection.js:4:1)
    at Module._compile (module.js:570:32)
    at loader (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:/project/landscapp/App/test/spinner.spec.js:6:1)
    at Module._compile (module.js:570:32)
    at loader (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (C:\project\landscapp\App\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at C:\project\landscapp\App\node_modules\mocha\lib\mocha.js:222:27
    at Array.forEach (native)
    at Mocha.loadFiles (C:\project\landscapp\App\node_modules\mocha\lib\mocha.js:219:14)
    at Mocha.run (C:\project\landscapp\App\node_modules\mocha\lib\mocha.js:487:10)
    at loadAndRun (C:\project\landscapp\App\node_modules\mocha\bin\_mocha:416:22)
    at Object.<anonymous> (C:\project\landscapp\App\node_modules\mocha\bin\_mocha:433:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

其他人是否遇到此错误,是否有人可以帮助我?

1 个答案:

答案 0 :(得分:0)

我通过在测试文件夹中的setup.js文件中添加以下行来修复此问题:

function noop() {
  return null;
}

require.extensions['.css'] = noop;
require.extensions['.scss'] = noop;
require.extensions['.md'] = noop;
require.extensions['.png'] = noop;
require.extensions['.svg'] = noop;
require.extensions['.jpg'] = noop;
require.extensions['.jpeg'] = noop;
require.extensions['.gif'] = noop;