I have a function as follows
import config from "../config";
export const encrypt = (recordJSONy, logger) => {
const key = config.encryption.key
if(!key || key == ""){
throw encryptionError.ENCYPTION_KEY_MISSING
}
try{
const decryptedDataStr = TisEncryption.Cipher.encrypt(recordJSON);
return decryptedDataStr;
} catch(e){
console.log(e)
throw encryptionError.ENCRYPTION_FAILED
}
}
I need to write a test for it
describe("help function test", () => {
it("test", () => {
console.log(helperFunctions.encrypt("xxx", loggingService))
});
});
However the above is always returning error because config.encryption.key returns undefined.
I am trying to find a way to kind of mock config.encryption.key to return "xxxxxxx" instead of undefined. The more I look at sinon the more I get confused. Can anyone shed light on how to do so?
question from:
https://stackoverflow.com/questions/65838433/using-sinon-to-mock-a-line-in-a-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…