Javascript 单元测试失败并出现错误“;Cypress命令超时';4000ms';超过”;

Javascript 单元测试失败并出现错误“;Cypress命令超时';4000ms';超过”;,javascript,reactjs,unit-testing,cypress,react-testing-library,Javascript,Reactjs,Unit Testing,Cypress,React Testing Library,我使用cypress和react测试库在我的组件上执行单元测试。但是,当测试执行时,我遇到了以下错误 “已超过Cypress命令超时'4000ms' 我注意到我编写的实际测试成功了。但是,不知何故插入的“毕竟”钩子中有一个错误。我的测试规范中没有“毕竟”钩子。我想知道可以从哪里调用它,因为我的代码中没有它 附加信息:我正在使用添加在plugins/index.js文件中的webpack和伊斯坦布尔插件 test-spec.js 从“React”导入React; 从'@testing librar

我使用cypress和react测试库在我的组件上执行单元测试。但是,当测试执行时,我遇到了以下错误

“已超过Cypress命令超时'4000ms'

我注意到我编写的实际测试成功了。但是,不知何故插入的“毕竟”钩子中有一个错误。我的测试规范中没有“毕竟”钩子。我想知道可以从哪里调用它,因为我的代码中没有它

附加信息:我正在使用添加在plugins/index.js文件中的webpack和伊斯坦布尔插件

test-spec.js

从“React”导入React;
从'@testing library/react'导入{render,firevent,cleanup};
从“../../src/utils/testUtils/components/Greeting”导入问候语;
描述('react-testing-library',()=>{
它('呈现视图详细信息组件',()=>{
const component=render();
getByText('Hello');
})
})
我的组件-greeting.js

从“React”导入React;
导出默认函数问候语(){
返回(
{'Hello'}
);
}
cypress\support\index.js

import./commands';
导入“@cypress/code coverage/support”;
cypress\plugins\index.js


const webpack=require(“@cypress/webpack预处理器”)
const webpackOptions={
模块:{
规则:[
{
测试:/\(js | jsx | mjs)$/,
加载器:“巴别塔加载器”,
选项:{
预设:['@babel/preset env','@babel/preset react'],
插件:['@babel/插件建议类属性','伊斯坦布尔'],
},
}
]
}
}
常量选项={
//从webpack.config.js发送选项,使其工作原理相同
//作为应用程序的代码
网页选项,
监视选项:{}
}
module.exports=on=>{
在('文件:预处理器',网页包(选项))
在('task',require('@cypress/code-coverage/task')上
}
下面是我在控制台上得到的错误

react-testing-library
    √ renders View Details component (68ms)
    1) "after each" hook for "renders View Details component"


  1 passing (7s)
  1 failing

  1) react-testing-library "after each" hook for "renders View Details component":
     Error: Cypress command timeout of '4000ms' exceeded.

Because this error occurred during a 'after each' hook we are skipping all of the remaining tests.
      at http://localhost:4444/__cypress/runner/cypress_runner.js:82978:25
因此,测试失败。任何关于为什么会发生这种错误的建议都会大有帮助


提前谢谢

在cypress社区的帮助下,react测试库似乎正在为清理添加每个挂钩之后的链接

这是一种异步方法,会导致cypress发出警告:

cypress_runner.js:85235 Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.
我能够防止这种增加的售后服务,并让测试工作。我们可以使用给出的任何一种方法来实现这一点