Chai-http 请求返回未定义
Chai-http request returning undefined
下面是我的代码:
server.js
const app = express();
app.listen(port, () => {
logger.info(`App running on http://localhost:${port}`);
});
export default app;
test.js
import server from "../../src/index.js";
chai.use(chaiHttp);
describe("GET Balance API Tests", () => {
beforeEach(() => {
const userBalance = mockUserBalances;
});
it("should return correct value", async () => {
const res = await chai.request(server).get("/balance/user-1");
console.log(res.status); // this correctly returns 200
res.status.should.equal(200); // this throws an error stating res is undefined
});
});
我在这里做错了什么?为什么每当我尝试做任何断言时 res 总是未定义?
因为 res.status
是“200”,我认为它不会有 should
属性。我认为正确的说法应该是这样的:
expect(res).to.have.status(200);
下面是我的代码:
server.js
const app = express();
app.listen(port, () => {
logger.info(`App running on http://localhost:${port}`);
});
export default app;
test.js
import server from "../../src/index.js";
chai.use(chaiHttp);
describe("GET Balance API Tests", () => {
beforeEach(() => {
const userBalance = mockUserBalances;
});
it("should return correct value", async () => {
const res = await chai.request(server).get("/balance/user-1");
console.log(res.status); // this correctly returns 200
res.status.should.equal(200); // this throws an error stating res is undefined
});
});
我在这里做错了什么?为什么每当我尝试做任何断言时 res 总是未定义?
因为 res.status
是“200”,我认为它不会有 should
属性。我认为正确的说法应该是这样的:
expect(res).to.have.status(200);