diff --git a/src/index.js b/src/index.js index a2a53fc..96da7ae 100644 --- a/src/index.js +++ b/src/index.js @@ -281,7 +281,7 @@ function getDir( language ) { * @return {string[]} list of language codes */ function getLanguagesInTerritory( territory ) { - return languageData.territories[ territory ]; + return languageData.territories[ territory ] || []; } /** diff --git a/tests/js/index.js b/tests/js/index.js index df48e8d..d95d1dd 100644 --- a/tests/js/index.js +++ b/tests/js/index.js @@ -142,6 +142,11 @@ describe( 'languagedata', function () { ], 'Correct regions of the Laz language were selected' ); assert.strictEqual( languageData.getRegions( 'no-such-language' ), 'UNKNOWN', 'The region of an invalid language is "UNKNOWN"' ); assert.ok( languageData.getLanguagesInTerritory( 'RU' ).includes( 'sah' ), 'Sakha language is spoken in Russia' ); + assert.deepEqual( + languageData.getLanguagesInTerritory( 'no-such-country' ), + [], + 'An invalid country has no languages and returns an empty array' + ); languagesAM = [ 'atj', 'chr', 'chy', 'cr', 'en', 'es', 'fr', 'gn', 'haw', 'ike-cans', 'ik', 'kl', 'nl', 'pt', 'qu', 'srn', 'yi' ]; assert.deepEqual(