等到柏树初始化变量

发布于 2025-02-09 20:30:11 字数 394 浏览 1 评论 0原文

我如何等到柏树中初始化变量?

例如,我有以下代码:

let width;
cy.get("[data-cy=foo-bar]")
  .should(element => (width = element.width()))
  .get("[data-cy=baz-baz]")
  //some other chained Cypress operations
  ...;

我想要行.getcy(“ Baz-baz”) no执行,直到设置width。我怎么能以最清洁的方式实现这一目标?

我想保留操作的链接并避免嵌套,因为以后我可能需要多个变量,并且将所有内容都放在应该中变得非常混乱。

How could I wait until a variable is initialized in Cypress?

E.g. I have the following code:

let width;
cy.get("[data-cy=foo-bar]")
  .should(element => (width = element.width()))
  .get("[data-cy=baz-baz]")
  //some other chained Cypress operations
  ...;

I would like the line .getCy("baz-baz") no to execute until the width was set. How could I achieve that in the cleanest way you know?

I would like to preserve the chaining of operations and avoid nesting, since I may require more than one variable later on and it becomes quite messy to put everything inside the should.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文