问题描述
我正在 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']");