首页 > 解决方案 > 在 reactjs 中使用 jest 编写单元测试时,对 MsalAuthenticationTemplate 的更新运行效果、错误

问题描述

我正在开玩笑地编写单元测试,我的单元测试正在运行,但我总是遇到错误。由于这个错误,它没有显示成功运行的覆盖率和测试描述

console.error
      Warning: An update to MsalAuthenticationTemplate ran an effect, but was not wrapped in act(...).
      
      When testing, code that causes React state updates should be wrapped into act(...):
      
      act(() => {
    /* fire events that update state */
  });
  /* assert on the output */
  
  This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
      at MsalProvider (C:\XXXXXX\node_modules\@azure\msal-react\src\MsalProvider.tsx:25:31)
      at ThemeProvider (C:\XXXXXX\node_modules\@material-ui\core\node_modules\@material-ui\styles\ThemeProvider\ThemeProvider.js:48:24)
      at Provider (C:\XXXXXX\node_modules\react-redux\lib\components\Provider.js:21:20)

任何人都面临同样的问题并且有 MsalAuthenticationTemplate 的示例模拟吗?

标签: reactjsjestjsjest-fetch-mockmsal-react

解决方案


推荐阅读