【发布时间】:2020-09-25 15:57:23
【问题描述】:
我正在阅读 Cypress 中的文档,我想我知道 then() 的作用。它像 Promise 一样工作,一个 Promise 返回另一个 Promise,但是使用 then(),我们返回一个新的主题。
如果我们看下面的代码示例,我们使用 then() 是因为我们正在返回一个新变量,在本例中称为 target。
我理解正确吗?如果没有,有人可以纠正我吗?
it.only('Marks an incomplete item complete', () => {
//we'll need a route to stub the api call that updates our item
cy.fixture('todos')
.then(todos => {
//target is a single todo, taken from the head of the array. We can use this to define our route
const target = Cypress._.head(todos)
cy.route(
"PUT",
`api/todos/${target.id}`,
//Here we are mergin original item with an object literal
Cypress._.merge(target, {isComplete: true})
)
})
【问题讨论】: