报错信息如下:
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
报错在这行 import 'highlight.js/styles/monokai.css'
应该是js/css文件没有转换好,
处理方式如下:
1.首先安装 babel-jest和 identity-obj-proxy文章来源:https://www.toymoban.com/news/detail-519898.html
yarn add babel-jest identity-obj-proxy -D
2.然后在package.json文件中的jest配置中加 moduleNameMapper
配置文章来源地址https://www.toymoban.com/news/detail-519898.html
{
"jest":{
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
到了这里,关于React + jest 测试 hightlight.js 报错的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!