Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 理解柏树中的then()_Testing_Cypress - Fatal编程技术网

Testing 理解柏树中的then()

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

我正在阅读Cypress中的文档,我想我对then()的作用有了一个想法。它就像承诺一样,一个承诺返回另一个承诺,但使用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})
             )
         })

。然后使用
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
})