【问题标题】:node.js:Previous test cases break, When I'm tring using http-chai modulenode.js:以前的测试用例中断,当我正在使用 http-chai 模块时
【发布时间】:2016-02-06 02:28:11
【问题描述】:

我没有使用单独的数据库进行生产和开发。首先,我尝试测试将我连接到 mongodb 的模块。这工作正常。我正在使用 chai 和 mocha 来做到这一点。

我的服务器文件的结构: 因此,当用户点击路由(即任何 url)时,路由回调调用模块对数据库执行操作。这是服务器文件的组织方式。

用户可以点击路由并获取/发布数据。我编写了测试用例来测试处理 mongodb 的模块,这很棒并且有效。

现在我正在尝试通过下面的代码测试我的路线,但是当我使用它时,我之前的断言会中断,如果我注释掉下面的代码,一切都会很好。

var serverAddress='http://localhost:8080';

    var chaiHttp = require('chai-http');
    chai.use(chaiHttp);

    describe('login/user', function() {
      it('should login user to the server', function(){
          chai.request(serverAddress)
              .post('/login/user')
              .send({ email: "sandeep@admin.com", password: "admin" })
              .then(function (res) {
                  expect(res).to.have.status(200);
              })
              .catch(function (err) {
                  throw err;
              })

      });
    });

错误如下:

Unhandled rejection AssertionError: expected 'AssertionError' to equal '*****'

我们将不胜感激。

【问题讨论】:

    标签: node.js mongodb unit-testing chai


    【解决方案1】:

    您发布的代码看起来不错。也许登录系统会导致任何测试失败的行为发生变化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多