Reputation: 5070
I would like to mock the resolved value of navigator.userAgentData.getHighEntropyValues
in my test to be a sample object.
How can I do this?
I tried:
beforeEach(() => {
jest.mock(global.navigator.userAgentData);
});
it('uaFullVersion is defined', async () => {
global.navigator.userAgentData.getHighEntropyValues.mockResolvedValueOnce({uaFullVersion: '1.2.3'});
const hev = await myFunc();
expect(hev.uaFullVersion).toBeDefined();
});
myFunc:
async function myFunc() {
const hev = await navigator.userAgentData.getHighEntropyValues(["uaFullVersion"]);
return hev;
}
but I get the error
TypeError: Cannot read properties of undefined (reading 'getHighEntropyValues')
Upvotes: 0
Views: 1106
Reputation: 54
have you tried using jest.spyOn
instead of the jest.mock
at the beforeEach
?
like:
jest.spyOn(global.navigator.userAgentData,
'getHighEntropyValues').mockResolvedValueOnce({})
?
Upvotes: 0