1 import { getCountryFromLanguage } from './useMyCountry';
3 describe('getCountryFromLanguage()', () => {
8 it('should prioritize languages as given by the browser', () => {
9 const mockNavigator = jest.spyOn(window, 'navigator', 'get');
10 mockNavigator.mockReturnValue({
12 languages: ['de-DE', 'en-EN'],
15 expect(getCountryFromLanguage()).toEqual('de');
18 it('should prioritize languages with country code', () => {
19 const mockNavigator = jest.spyOn(window, 'navigator', 'get');
20 mockNavigator.mockReturnValue({
22 languages: ['fr', 'en_CA'],
25 expect(getCountryFromLanguage()).toEqual('ca');
28 it('should return undefined when the browser language tags do not have country code', () => {
29 const mockNavigator = jest.spyOn(window, 'navigator', 'get');
30 mockNavigator.mockReturnValue({
32 languages: ['fr', 'en'],
35 expect(getCountryFromLanguage()).toBeUndefined();