在接下来使用情感/风格与玩笑和反应测试库测试组件时出错

问题描述 投票:0回答:1

我正在测试一个具有以下代码并使用@emotion/styled的组件:

import styled from "@emotion/styled";

const StyledNavBar = styled.div`
  position: fixed;
  top: 0;
  width: calc(100% + 1rem);
`;

const NavBar = (props) => {};

(注:出于隐私考虑,我不提供更多代码)

我面临的错误是:

我的一些依赖:

{
  "dependencies": {
    "@emotion-icons/material": "^3.14.0",
    "@emotion-icons/material-outlined": "^3.14.0",
    "@emotion-icons/material-rounded": "^3.14.0",
    "@emotion/react": "^11.9.3",
    "@emotion/styled": "^11.9.3",
    "@next/bundle-analyzer": "^13.4.19",
    "@next/env": "^13.5.6",
    "jest-emotion": "^11.0.0",
    "next": "13.4.12",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@emotion/jest": "^11.11.0",
    "@testing-library/jest-dom": "^6.2.0",
    "@testing-library/react": "^14.1.2",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-styled-components": "^7.2.0"
  }
}

我使用的是节点v20.9.0

你知道这个错误有什么解决办法吗?

我更改了一些笑话配置,但它们不起作用

next.js jestjs react-testing-library emotion
1个回答
0
投票

我通过将其添加到我的

jest.config.js
文件中来解决:

 transformIgnorePatterns: [
    '/node_modules/(?!@emotion/styled/.*)',
    '/node_modules/(?!@newscorp.*)',
  ],
© www.soinside.com 2019 - 2024. All rights reserved.