Cannot read property 'salt' of null in CryptoJS.AES.decrypt

1.7k Views Asked by At

i am testing my application using jest on vuejs. I am getting an error as TypeError: Cannot read property 'salt' of null when I decrypt a string using crypto-js.

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

when the test is run it runs checkingRoutes function

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

how to solve the issue on @vue/test-utils

1

There are 1 best solutions below

0
On

I solved the issue by mocking the exact function here is the example below

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']");