【问题标题】:How to resolve error: not assignable to parameter of type '"disconnect"'?如何解决错误:不可分配给“断开连接”类型的参数?
【发布时间】:2020-11-24 21:44:34
【问题描述】:

我有以下测试,我想在其中发出一个特定事件,即 unhandledRejection 过程:

    describe('Processes Tests', () => {
    afterEach(() => {
        sinon.restore();
    });
it('Check unhandledRejection process Spied On', () => {
        var spy = sinon.spy();
        process.on('unhandledRejection', spy);
        process.emit('unhandledRejection');
        sinon.assert.calledOnce(spy);
      });
});

我在process.emit('unhandledRejection')这一行出现以下错误:

Argument of type '"unhandledRejection"' is not assignable to parameter of type '"disconnect"'.

可能有人知道这是为什么以及我如何能够解决它以便我可以测试这个过程?提前致谢!

【问题讨论】:

    标签: node.js typescript mocha.js chai sinon


    【解决方案1】:
    describe('Processes Tests', () => {
        afterEach(() => {
            sinon.restore();
        });
        it('Check unhandledRejection process Spied On', () => {
            var spy = sinon.spy();
            process.on('unhandledRejection', spy);
            process.emit('unhandledRejection', 'reason', new Promise(() => {}));
            sinon.assert.calledOnce(spy);
        });
    });
    

    你又忘记了 2 个参数

    我在documentation没有找到关于这个方法的,但是我确实在types找到了

    【讨论】:

      猜你喜欢
      • 2022-06-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 2021-09-10
      • 2021-10-18
      • 2019-09-23
      • 2018-10-19
      相关资源
      最近更新 更多