当我尝试渲染组件时,我在玩笑测试中不断收到此错误

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

子组件时出现错误。

在这里是测试:
import renderer from 'react-test-renderer'
import React from 'react'
import LogContainer from '../logsContainer/LogContainer'
import { createMemoryHistory } from 'history'

it('Renders normally', async () => {
  const component = renderer.create(
    <LogContainer log={[{message:'Hello'},{message:'World'}]} setLog={() => {}}/>
  )
  let tree = component.toJSON()
  expect(tree).toMatchSnapshot()
})

当这样定义时,错误会弹出:

LogContainer

但是错误

当我省略

import {Typography,IconButton } from '@mui/material'; import Box from '@mui/material/Box'; export type LogMsg = { message: string, error?: boolean, success?: boolean, warning?: boolean } type Props = { autoScroll?: boolean, log: LogMsg[], setLog: (newLog: LogMsg[]) => void } export default function LogContainer ({autoScroll, log, setLog}:Props) { return( <Box sx={{width: '50em'}}> <Typography> {('Logs : ')} </Typography> <IconButton title='Clear' aria-label="delete"/> </Box> ) }
时,没有出现

为什么是那个?是什么使
<IconButton/>

负责崩溃测试并丢弃此错误? (给定
<IconButton/>

Typography来自同一库)。 我尝试过的thins

将测试定为
IconButton

指定文件的顶部

async
/** @jest-environment jsdom */

setImmediate

  • 没有解决问题。
    	
  • 将错误更新到其(当前)上一个版本时,错误消失了:
  • @testing-library
  • 对于我来说,它没有在屏幕前面。
        
reactjs jestjs
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.