Asynchronous 异步完成()在moch-chai中不工作。无法访问http响应

Asynchronous 异步完成()在moch-chai中不工作。无法访问http响应,asynchronous,mocha.js,chai,chai-http,Asynchronous,Mocha.js,Chai,Chai Http,我试图遵循此处提供的内容- 尽管我使用done()添加了回调,但首先执行it步骤中的日志。但是,在这之后,我可以看到chai块内部的日志,其中包含预期值,然后是done,这不是一个函数错误 printing from next step undefined property1 value1 property2 value2 property1 value1 property2 value2 1) Scenario: my api test And: I manipulate API R

我试图遵循此处提供的内容-

尽管我使用done()添加了回调,但首先执行
it
步骤中的日志。但是,在这之后,我可以看到chai块内部的日志,其中包含预期值,然后是
done,这不是一个函数
错误

printing from next step undefined
property1  value1
property2  value2
property1  value1
property2  value2

1) Scenario: my api test And: I manipulate API REsponse data:
 Cannot read property 'metadata' of undefined
 TypeError: Cannot read property 'metadata' of undefined

2) Scenario: my api test "after each" hook:
 done is not a function
 TypeError: done is not a function

我的目标是将响应存储在一个对象中,并在接下来的多个步骤中访问它。

我也不确定为什么“每个”挂钩之后:会显示在错误日志中。在输出中,您提到了“每个”挂钩之后,但您的初始代码块只包含一个“每个”挂钩之前。你是说你的“before”钩子吗?我只在代码中定义了“before”钩子。但是我的输出显示了关于“aftereach”钩子的错误日志,我没有定义这些钩子。
describe('Scenario: my api test', () => {
  
    let apiResponse;
 
    before('before', function(done)  {
      let chai = require('chai');
      let chaiHttp= require('chai-http')
      chai.use(chaiHttp);
      chai.request(serverurl)
          .get(/endPoint)
          .end(function(err, res) {
            apiResponse = res.body;
            console.log('property1', res.body.metadata.property1)
            console.log('property2', res.body.metadata.property2)
            console.log('property1',apiResponse.metadata.property1)
            console.log('property2', apiResponse.metadata.property2)
            done();
          })   });
  
  
    it('And: I manipulate API REsponse data',() => {
      console.log('printing from next step', apiResponse);
      console.log('printing from next step', apiResponse.metadata.someProperty);
    })
     })
printing from next step undefined
property1  value1
property2  value2
property1  value1
property2  value2

1) Scenario: my api test And: I manipulate API REsponse data:
 Cannot read property 'metadata' of undefined
 TypeError: Cannot read property 'metadata' of undefined

2) Scenario: my api test "after each" hook:
 done is not a function
 TypeError: done is not a function