0

What's the best way to specify navigator language while running jest tests? I have a function calling toLocaleString, but it returns different values based on the language of the navigator.

I have tried

beforeEach(() => {
    jest.spyOn(global.navigator, 'language', 'get').mockReturnValue('en-US')
})

However, it gives me the error Cannot spyOn on a primitive value

aakashgupta.0205
  • 647
  • 1
  • 8
  • 23
  • Related to https://stackoverflow.com/questions/36568883/mock-navigator-language-in-specific-tests – Lin Du Sep 09 '22 at 10:27

0 Answers0