无法读取 CryptoJS.AES.decrypt 中的 null 属性“盐”

问题描述

我正在 vuejs 上使用 jest 测试我的应用程序。当我使用 TypeError: Cannot read property 'salt' of null 解密字符串时,我收到 crypto-js 错误

test("DASHBOARD ACCESS PERMISSION",async () => {
    let wrapper = mount(Dashboard,{
      stubs: ["router-link","router-view"],vuetify,router,localVue,});
    wrapper.vm.checkingRoutes();
  });

当测试运行时,它运行 checkingRoutes 函数

let key = 'abcd'
var bytes = CryptoJS.AES.decrypt('encripted key is here',key);
var data = bytes.toString(CryptoJS.enc.Utf8);
console.log(data)

如何解决@vue/test-utils 上的问题

解决方法

我通过模拟下面的示例来解决这个问题

globalFunctions => // helper or defined as global
DecKey          => // exact function that trigger to solve the issue

const decryptData = jest.spyOn(globalFunctions,"DecKey");
decryptData.mockImplementation(() => "['passing_values']");

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...