Typescript Chai.request不是一个函数
我有以下简单的代码Typescript Chai.request不是一个函数,typescript,mocha.js,chai,chai-http,Typescript,Mocha.js,Chai,Chai Http,我有以下简单的代码 import app from '../src/app'; import * as chai from 'chai'; import chaiHttp = require('chai-http'); chai.use(chaiHttp); const expect = chai.expect; describe('Get /', () => { it('Should say hi there', async () => { const
import app from '../src/app';
import * as chai from 'chai';
import chaiHttp = require('chai-http');
chai.use(chaiHttp);
const expect = chai.expect;
describe('Get /', () => {
it('Should say hi there', async () => {
const response = chai.request(app).get('/');
console.log(response);
expect(5).to.equal(5);
});
});
每次我跑步
mocha -r ts-node/register lib/tests/**/sample.spec.ts
我得到以下错误
TypeError:chai.request不是函数
我用同样的问题看了其他stackoverflow帖子。他们都说,
chai.use(chaiHttp)
应该解决这个问题
但是,正如你所看到的,我已经有了
有什么想法吗
tsconfig.json
中的esModuleInterop
为false
,它应该可以正常工作从“chai”导入*作为chai;
导入chaiHttp=require('chai-http');
柴胡;柴胡;
const expect=chai.expect;
描述('Get/',()=>{
它('Should say hi there',async()=>{
expect(chai.request).to.be.a('function');
});
});
测试结果:
Get /
✓ Should say hi there
1 passing (4ms)
esModuleInterop
为true
,则应使用import chai from'chai'代码>而不是使用导入*作为来自“chai”的chai代码>
与chai一起使用chai http
const chai = require("chai");
const chaiHttp = require("chai-http");
然后
chai.use(柴胡汤)代码>
这对我很有用。你能试着这样导入吗:从“chai”导入chai代码>