簡體   English   中英

如何在 cypress 中加入 2 個不同的斷言?

[英]How to join 2 different assertions in cypress?

伙計們。 您知道如何連接 2 個不同的斷言嗎?

  assert.isNotNull(res.body, "is not null");
  assert.isNotNull(res.body.createdAt, "is not null");

參考: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

將你的斷言包裹在Promise.all

Promise.all([
  assert.isNotNull(res.body, "is not null"),
  assert.isNotNull(res.body.createdAt, "is not null")
])

您傳遞了一系列斷言。 兩者都必須通過才能通過斷言。

您可以將expect chai 斷言與&&一起使用,例如:

expect(res.body).to.not.be.null && expect(res.body.createdAt).to.not.be.null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM