简体   繁体   English

Mocha /应该“未定义不是函数”

[英]Mocha/Should 'undefined is not a function'

I'm going off of this tutorial, trying to make tests with Mocha, Supertest, and Should.js. 我将退出教程,尝试使用Mocha,Supertest和Should.js进行测试。

I have the following basic test to create a user through a PUT endpoint that accepts it's data in headers. 我进行了以下基本测试,以通过在标头中接受其数据的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();
            });
        });

However, while the endpoint does trigger, and the user does get made, the code throws an error that should is undefined... Uncaught TypeError: undefined is not a function . 但是,尽管端点确实触发了并且用户确实成功了,但是代码抛出了should是未定义的错误…… Uncaught TypeError: undefined is not a function

I have 我有

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

At the top of the file, so why would it be undefined? 在文件的顶部,为什么为什么未定义呢?

You are calling should incorrectly, try this: 您拨打的电话不正确,请尝试以下操作:

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

or 要么

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

or 要么

should.equal(res.status, 201)

or install should-http . 或安装should-http

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM