Testing 理解柏树中的then()
我正在阅读Cypress中的文档,我想我对then()的作用有了一个想法。它就像承诺一样,一个承诺返回另一个承诺,但使用then(),我们返回了一个新的主题 如果我们看下面的代码示例,我们使用then(),因为我们返回一个新变量,在本例中称为target 我理解正确吗?如果没有,有人能纠正我吗Testing 理解柏树中的then(),testing,cypress,Testing,Cypress,我正在阅读Cypress中的文档,我想我对then()的作用有了一个想法。它就像承诺一样,一个承诺返回另一个承诺,但使用then(),我们返回了一个新的主题 如果我们看下面的代码示例,我们使用then(),因为我们返回一个新变量,在本例中称为target 我理解正确吗?如果没有,有人能纠正我吗 it.only('Marks an incomplete item complete', () => { //we'll need a route to stub the ap
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})
)
})
。然后使用
从cy.fixture('todos')
接收结果。变量target
在此代码中不重要
在您的代码示例中,从cy.fixture
返回的变量名为todos
——代码的间距可能会使您在这里出错?。然后
调用被附加到cy.fixture()
调用
// These 2 code blocks are the same - just different spacing
cy.fixture('todos')
.then(todos => {});
cy.fixture('todos').then(todos => {});
cy.fixture('logo.png').then((logo) => {
// load data from logo.png
})