title: How to mock window.navigator.language using jest
body: <p>I am trying to mock the <code>window.navigator.language</code> attribute in the browser in my jest unit tests so I can test that the content on my page is using the correct language</p>
  
  <p>I have found people online using this:</p>
  
  <p><code>Object.defineProperty(window.navigator, 'language', {value: 'es', configurable: true});</code></p>
  
  <p>I have set it right at the top of my test file and it is working there</p>
  
  <p>however, when I redefine in an individual test (and people set to make sure configurable was set to true) it wont redefine it and is just using the old value, does anyone know a way to definitely change it?</p>
  
  <pre><code>beforeEach(() =&gt; {
      jest.clearAllMocks()
      Object.defineProperty(global.navigator, 'language', {value: 'es', configurable: true});
      wrapper = shallow(&lt;Component {...props} /&gt;)
  })
  
    it('should do thing 1', () =&gt; {
        Object.defineProperty(window.navigator, 'language', {value: 'de', configurable: true});
        expect(wrapper.state('currentLanguage')).toEqual('de')
      })
  
  it('should do thing 2', () =&gt; {
    Object.defineProperty(window.navigator, 'language', {value: 'pt', configurable: true});
    expect(wrapper.state('currentLanguage')).toEqual('pt')
  })
  </code></pre>
  
  <p>for these tests it is not changing the language to the new language I have set, always using the one at the top</p>