开玩笑:为什么它会因SyntaxError:Unexpected token而失败. CSS类? [英] Jest: why does it fail with SyntaxError: Unexpected token . for css class?

查看:377
本文介绍了开玩笑:为什么它会因SyntaxError:Unexpected token而失败. CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个React应用程序,并开玩笑地编写了单元测试.

I wrote a React application and used jest to write unit tests.

当我通过"jest --config = jest.config.json --watch"运行它时,出现以下错误:

when I run it by "jest --config=jest.config.json --watch" I get the following error:

测试套件无法运行

/home/user/Projects/react-game/src/Square.css:1
({"Object.>

:功能(模块,导出,要求,__ dirname,__ filename,global,jest){.bluePawn, .blueMasterPawn,.redPawn,.redMasterPawn { ^ SyntaxError:意外令牌.

":function(module,exports,require,__dirname,__filename,global,jest){.bluePawn, .blueMasterPawn, .redPawn, .redMasterPawn { ^ SyntaxError: Unexpected token .

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/MasterPawn.js:3:1)
  at Object.<anonymous> (src/Utils.js:3:19)

我只想指出编译器将标记".bluePawn",这是一个类名.因此,我知道它无法读取类名.

I just want to note that compiler marks ".bluePawn" which is a class name. Therefore, I understand that it cannot read class name.

看起来与配置有关. 我在网上搜索,没有找到任何可以帮助我的解决方案.

It looks like something that has to do with configurations. I was searching on the web, and didn't find any solution that could help me.

推荐答案

src内创建一个名为stub.css的空css文件.

Create an empty css file named stub.css inside src.

然后将其添加到您的package.json:

"jest": {
    "moduleNameMapper": {
      ".*css$": "<rootDir>/src/stub.css",
    },

这篇关于开玩笑:为什么它会因SyntaxError:Unexpected token而失败. CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆