1

我有一个非常简单的 GET 测试,通过 Mocha 运行

import chai from 'chai'
import chaiHttp from 'chai-http'
import {should, expect} from 'chai'
import nock from 'nock'
import request from 'supertest'

    const url  = 'http://mysite-beta.com'
    const api = '/api/user'


    describe('/GET route', () => {
        it('it should GET the mocked response', (done) => {      
            nock(url)
            .get(api)
            .reply(200, {
              "status": 200,
              "message": "This is a mocked response"
            });

          request(url)
            .get(api)
            .end(function (err, res) {
              // ****** the next line gives an error ******
              expect(res.body.status).to.equal(200);
              expect(res.body.message).to.equal("This is a mocked response");
              done();
            });
        });
      });

但是当我运行它时,我得到TypeError: Cannot read property 'body' of undefined. res 未定义 一切都已设置好,例如 npm 包等

4

0 回答 0