Javascript react测试库:调试的一部分';的输出不可见
我正在使用react jest和react测试库来测试我的组件。 我面临一个奇怪的问题。我正在使用测试库中呈现的调试返回Javascript react测试库:调试的一部分';的输出不可见,javascript,reactjs,jestjs,react-testing-library,Javascript,Reactjs,Jestjs,React Testing Library,我正在使用react jest和react测试库来测试我的组件。 我面临一个奇怪的问题。我正在使用测试库中呈现的调试返回 test('component should work', async () => { const { findByText, debug } = render(<MyComponent />); const myElement = await findByText(/someText/i); debug(); }); test('compo
test('component should work', async () => {
const { findByText, debug } = render(<MyComponent />);
const myElement = await findByText(/someText/i);
debug();
});
test('component should work',async()=>{
const{findByText,debug}=render();
const myElement=wait findByText(/someText/i);
调试();
});
正如您在屏幕截图中所看到的,缺少不完整的开发和父级关闭标记。您需要更改
DEBUG\u PRINT\u LIMIT
env变量的值(默认值为7000)
例如,使用以下选项运行测试:DEBUG\u PRINT\u LIMIT=10000纱线测试
来源:可以使用
debug()
函数的第二个参数设置maxLengthToPrint
例如,要在myElement中打印所有内容,请使用:
从'@testing library/react'导入{render,screen}
render();
const myElement=wait screen.findByText(/someText/i);
常量MaxLengthTopPrint=100000
screen.debug(myElement,MaxLengthTopPrint);
见:
- 这对我很有效
const history = createMemoryHistory()
const { debug } = renderWithRedux(
<Router history={history}>
<SideBar />
</Router>
, state);
screen.debug(debug(), 20000);
const history=createMemoryHistory()
const{debug}=renderWithRedux(
,国家);
screen.debug(debug(),20000);
我正在使用此版本:“@testing library/react”:“^11.0.4”
可以像下面这样做,我们可以将300000更改为输出的最大长度
debug(undefined, 300000)
在@Haryono的答案之上添加 还要确保脚本中没有设置静默标志
"test": "jest --config jest.config.js --silent";
删除静默标志应该可以工作
注意:我认为静默标志禁止警告和调试输出您是否尝试过增加@uday中提到的
debug\u PRINT\u LIMIT
,仍然是相同的问题。debug(undefined,300000)
@J.Munson为什么undefined
?基本上是为了让typescript满意。但一般来说,undefined
是Javascript中省略参数的标准方法。