jeudi 23 mai 2019

Can't mock a library value when snapshot testing with jest

I am using `detect-browser' library in React component. I have as following:

export const browser = detect();

And inside component:

browser.name

I am writing an test for this one (snapshot) and i receive an error:

TypeError: Cannot read property 'name' of null

This is as I guess because I need to store a mock name from this library. I tried like this but get errors all the time

jest.mock('detect-browser', () => () => ({
  detect: () => {browser{name: 'edge'}},
}));

How this should be mocked properly ? Or I should do it in a different way?

Aucun commentaire:

Enregistrer un commentaire