无法使用 Chai-http

问题描述

我正在学习使用 mocha 和 chai 为节点应用程序编写测试用例,我编写了以下测试用例

let chai = require('chai');
let chaiHttp = require('chai-http');

const should = chai.should;
const expect = chai.expect;
const server = "http:\\localhost:3000"

chai.use(chaiHttp);

describe('Create Login and Register',() => {
    it('should login using credentials',() => {
        chai.request(server)
            .get('/register')
            .send()
            .then((res: any) => {
                res.should.have.status(200);
                done();
            }).catch((err: any) => { done(err) })
    })

})

但它显示了 done() 下方的读取摆动;功能

enter image description here

我需要为它添加一些类型才能工作我缺少什么吗,我尝试再次安装 chai-http 但仍然是同样的问题

解决方法

var controllerActionList = assembly.GetTypes() .Where(type => typeof(Controller).IsAssignableFrom(type)) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Select(x => new { Area = x.DeclaringType?.CustomAttributes.Where(c => c.AttributeType == typeof(AreaAttribute)),Controller = x.DeclaringType,Action = x }).ToList(); foreach (var item in controllerActionList) { var controleerDisplayName = item.Controller.GetTypeInfo().GetCustomAttribute<DisplayNameAttribute>()?.DisplayName; } 作为测试函数的第一个参数传入。

done

虽然,因为您使用的是 describe('Create Login and Register',() => { it('should login using credentials',(done) => { // <-- here chai.request(server) .get('/register') .send() .then((res: any) => { res.should.have.status(200); done(); }).catch((err: any) => { done(err) }) }) }) 链,所以您应该只返回该链。

Promise

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...