使用Emit套接字io时摩卡无法完成

时间:2018-08-23 18:27:14

标签: javascript node.js unit-testing socket.io mocha

您好,我正在使用Mocha进行单元测试,一切正常,直到使用io.emit测试方法为止,您可以在下面看到我的代码:

var emit = (type, to, content, url) => {
    var f = false;
    var io = require("../index").io;
    var socketIds = global.socketIds;
    if (socketIds && socketIds[to]) {
        let sockets = socketIds[to];
        for(let item of sockets){
            io.to(item).emit(type, { type: type, content: content, url: url });
            f = true;
        }
    }
    return f;
};

这是我的测试代码:

describe("create new notification with offline account", () => {
    it("it should be return a notification and offline status", done => {
            const save = global.socketIds;
            global.socketIds = {};
            callService(expected.notification, result => {
                Notification.findOne(expected.notification, (err, noti) => {
                    expect(result.online).to.equal(expected.online);
                    expect(noti).to.exist;
                    global.socketIds = save;
                    done();
                });
            });
        });
});

Mocha not finish and stop here

  • 摩卡版本:5.2.0

0 个答案:

没有答案