emoji-flags-to-country
Version:
Convert emoji country flags to country code.
35 lines (33 loc) โข 1.73 kB
JavaScript
const assert = require('assert');
const { flagToCountry, getFlagsInText } = require('../index');
describe('Tests for emoji flags to country code', () => {
it('should return undefined for empty inputs', () => {
assert.strictEqual(flagToCountry(''), undefined);
assert.strictEqual(flagToCountry(null), undefined);
assert.strictEqual(flagToCountry(undefined), undefined);
});
it('should return undefined for any character that is not a flag emoji', () => {
assert.strictEqual(flagToCountry('hello world'), undefined);
assert.strictEqual(flagToCountry('US'), undefined);
assert.strictEqual(flagToCountry('๐'), undefined);
});
it('should return the correct country code for a given emoji flag', () => {
assert.strictEqual(flagToCountry('๐ฎ๐น'), 'IT');
assert.strictEqual(flagToCountry('๐บ๐ธ'), 'US');
assert.strictEqual(flagToCountry('๐ช๐ธ'), 'ES');
assert.strictEqual(flagToCountry('๐ช๐บ'), 'EU');
});
it('should return an empty array for an invalid text', () => {
assert.deepEqual(getFlagsInText(''), []);
assert.deepEqual(getFlagsInText(null), []);
assert.deepEqual(getFlagsInText(undefined), []);
});
it('should return an empty array for a text with no emoji flags', () => {
assert.deepEqual(getFlagsInText('This text has no emoji flags ๐'), []);
});
it('should return an array of emoji flags for a text with emoji flags', () => {
const phrases = ['Italians do it better ๐ฎ๐น', '๐ฎ๐น some flag ๐บ๐ธ here and there๐ช๐ธ and also ๐ช๐บ'];
assert.deepEqual(getFlagsInText(phrases[0]), ['๐ฎ๐น']);
assert.deepEqual(getFlagsInText(phrases[1]), ['๐ฎ๐น', '๐บ๐ธ', '๐ช๐ธ', '๐ช๐บ']);
});
});