【问题标题】:Mocha/Should 'undefined is not a function'摩卡/应该“未定义不是函数”
【发布时间】:2015-11-16 08:11:56
【问题描述】:

我即将结束 this 教程,尝试使用 Mocha、Supertest 和 Should.js 进行测试。

我有以下基本测试通过PUT 端点创建用户,该端点接受标头中的数据。

describe('User Routes', function () {
    it('should allow me to make my user', function (done) {
        request(url)
        .put('/users')
        .set(myCreds)
        // end handles the response
        .end(function(err, res) {
              if (err) {
                throw err;
              }
              // this is should.js syntax, very clear
              res.should.have.status(201);
              done();
            });
        });

但是,虽然端点确实触发了,并且用户确实成功了,但代码会抛出 should 未定义的错误...Uncaught TypeError: undefined is not a function

我有

var should = require('should');
var assert = require('assert');
var request = require('supertest');

在文件的顶部,为什么它是未定义的?

【问题讨论】:

  • 1.) 只是为了排除这种可能性,您确定您已经安装了required 软件包吗? (npm install --save-dev should assert supertest) 2.) 抛出异常时res的值是多少?

标签: javascript mocha.js should.js


【解决方案1】:

你的调用应该是错误的,试试这个:

res.should.have.property('status', 201)

res.status.should.be.equal(201)

should.equal(res.status, 201)

或安装should-http

【讨论】:

  • 嗯,好的,谢谢。 should.not 非常信任本教程。当它允许我时会接受。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
相关资源
最近更新 更多