我想为我的应用编写一些单元测试,是否可以以某种方式“模拟”与require('dependencyname')一起使用的某些依赖项?
这是代码:
    var kk = JSON.stringify(object);
    console.log(kk);
    var kk1 = encrypt(kk);
    console.log(kk1)
    var kk2 = decrypt(kk1);
    console.log(kk2)
    this.write(encrypt(kk))
Run Code Online (Sandbox Code Playgroud)
功能:
var encrypt = function (data) {
    var cipher = crypto.createCipher('aes-256-ecb', password)
    cipher.update(data, 'utf8')
    return cipher.final('hex')
}
var decrypt = function (data) {
    var cipher = crypto.createDecipher('aes-256-ecb', password)
    cipher.update(data, 'hex')
    return cipher.final('utf8')
}
Run Code Online (Sandbox Code Playgroud)
控制台消息:
{"action":"ping","ping":30989}
4613a3a8719c921eed61e19b7480de9c
,"ping":30989}
Run Code Online (Sandbox Code Playgroud)
为什么解密不会导致初始字符串?