我正在为我的 react.js 项目使用 Jest 测试库。我也想用它来测试我的 Node.js 应用程序,我已经尝试了很多例子,但仍然所有的笑话例子都不起作用。
使用 Mocha & Chai 测试 socket.io 连接的一个示例有效,但是当我使用 Jest 时,它成功连接到 socket.io 服务器,并且发出了事件,但无法侦听。我还更新了这两种情况下的 socket.io 包。
这是使用 mocha & chai https://github.com/agconti/socket.io.tests的示例
这是我的代码:
索引.js
var express = require("express"),
app = express(),
port = process.env.PORT || 9000,
http = require("http").Server(app),
io = require("socket.io")(http);
io.on("connection", function(socket) {
console.log("connected");
socket.on("message", function(msg) {
console.log("emitted");
io.sockets.emit("message", msg);
});
});
// export the server so it can be easily called for testing
exports.server = http.listen(port);
Run Code Online (Sandbox Code Playgroud)
index.test.js
jest.setTimeout(50000);
var server = require("../index"),
io …Run Code Online (Sandbox Code Playgroud) 大家好,请告诉我这个参数在 PDO fetchAll 函数 fetchAll(PDO::FETCH_OBJ); 中意味着什么;我在手册中查找过它,但我没有找到任何相关信息,我是从教程中得到它的,但我不知道它意味着什么