【问题标题】:Node - Test if function call with 2 arguments using mocha/chai节点 - 使用 mocha/chai 测试是否有 2 个参数的函数调用
【发布时间】:2021-06-29 09:42:16
【问题描述】:

如何使用 mocha/chai 测试函数调用是否带有 2 个参数?

describe('EncryptCode Test', () => {

   it('EncryptCode function return a string', () => {
    expect(EncryptCode.Encrypt('fArgs','sArgs')).to.be.an('string');
   });

   it('EncryptCode function call with 2 arguments', () => {
     ???????????
   });

});

【问题讨论】:

    标签: node.js reactjs mocha.js chai


    【解决方案1】:

    您可以对字符串化函数声明进行一些分析/操作。

    let args = EncryptCode.Encrypt.toString().match(/\((.*)\)/)[1].split(',');
    expect(args).length(2);
    

    【讨论】:

    • 最好在您的代码 sn-ps 中添加支持文本,这样它们就不会被标记为删除
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    相关资源
    最近更新 更多