Javascript 笑话测试需要很长时间才能完成

Javascript 笑话测试需要很长时间才能完成,javascript,ecmascript-6,jestjs,react-testing-library,Javascript,Ecmascript 6,Jestjs,React Testing Library,我希望在我们的测试套件中进行一些清理,并遇到以下代码: const form=screen.getByTestId(elements.form); const firstName=screen.getByTestId(elements.firstName); const lastName=screen.getByTestId(elements.lastName); const email=screen.getByTestId(elements.email); const password=scr

我希望在我们的测试套件中进行一些清理,并遇到以下代码:

const form=screen.getByTestId(elements.form);
const firstName=screen.getByTestId(elements.firstName);
const lastName=screen.getByTestId(elements.lastName);
const email=screen.getByTestId(elements.email);
const password=screen.getByTestId(elements.password);
const confirmPassword=screen.getByTestId(elements.confirmPassword);
const telephone=screen.getByTestId(elements.telephone);
const dobDay=screen.getByRole('option',{name:'05'});
const dobMonth=screen.getByRole('option',{name:'April'});
const dobYear=screen.getByRole('option',{name:'1990'});
类型(firstName,'TestingFirstName');
类型(lastName,'TestingLastName');
userEvent.type(电子邮件,'testing@email.com');
userEvent.type(密码'Password123');
类型(confirmPassword,'Password123');
userEvent.type(电话“07888888”);
userEvent.click(dobDay);
userEvent.click(月);
userEvent.click(年份);
这些查询和操作在同一个descripe块中重复数次,这导致每个测试运行7-10秒。整体而言,我们整个套件的运行时间增加了一倍

是否有一种方法可以简化此过程,使其只运行上述一次?或者缓存上述内容以便下次使用时更快?或者任何能让事情加快一点的事情


非常感谢

你的意思是上面的整个代码块都在重复吗?如果是,为什么?@Christian是-这不是我的代码,我只是看到相关代码的测试需要将近一分钟的时间才能完成,所以我想仔细看看以了解原因。因此,由于上述操作重复多次,因此需要花费大量时间才能完成。但我不认为即使是一个测试也需要7-10秒才能完成?所以我希望我能一石二鸟。我只是不确定从哪里开始UI测试通常需要相当长的时间,但7-10秒听起来有点太长了。首先,我会尝试理解为什么会重复这些操作(除非每次都测试不同的屏幕?),一个错误的修复方法是设置一个标志,指示它已执行,然后阻止连续运行。@我猜在每次测试中,组件都会被清理并重新呈现,因此必须再次运行这些操作。我的印象是,可能是查询占用了很多时间,但实际上是userEvents。