Skip to content

Commit

Permalink
test(i18n-ptBR): 🥳 add test for firstName
Browse files Browse the repository at this point in the history
  • Loading branch information
kabrunko-dev committed Dec 14, 2023
1 parent 1d27fda commit e353b10
Showing 1 changed file with 71 additions and 5 deletions.
76 changes: 71 additions & 5 deletions packages/falso/src/tests/first-name.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { randFirstName } from '../lib/first-name';
import { data } from '../lib/first-name.json';
import { data as locale } from '../lib/i18n/ru/first-name.i18n.json';

import { data as locale_ru } from '../lib/i18n/ru/first-name.i18n.json';
import { data as locale_ptBR } from '../lib/i18n/pt-br/first-name.i18n.json';
import { NameOptions } from '../lib/full-name';

describe('firstName', () => {
let specialCharRegex: RegExp;
Expand Down Expand Up @@ -137,13 +140,13 @@ describe('firstName', () => {
});
});

describe('with provided locale data', () => {
const data = locale;
describe('with provided locale RU data', () => {
const data = locale_ru;

it('should works with female gender and provided data', () => {
const result = randFirstName({
gender: 'female',
locale,
locale: data,
});

expect(data.withoutAccents.female.includes(result)).toBe(true);
Expand All @@ -152,10 +155,73 @@ describe('firstName', () => {
it('should works with male gender and provided data', () => {
const result = randFirstName({
gender: 'male',
locale,
locale: data,
});

expect(data.withoutAccents.male.includes(result)).toBe(true);
});
});

describe('with provided locale PT-BR data', () => {
const data = locale_ptBR;
let options: NameOptions;

describe('female name', () => {
beforeEach(() => {
options = {
gender: 'female',
locale: data,
};
});

it('should return a firstName with at least 1 accented character', () => {
const result = randFirstName({
...options,
withAccents: true,
});

expect(result.match(specialCharRegex)).toBeTruthy();
expect(data.withAccents.female.includes(result)).toBe(true);
});

it('should return a firstName with only non-accented characters', () => {
const result = randFirstName({
...options,
withAccents: false,
});

expect(result.match(specialCharRegex)).toBeFalsy();
expect(data.withoutAccents.female.includes(result)).toBe(true);
});
});

describe('male name', () => {
beforeEach(() => {
options = {
gender: 'male',
locale: data,
};
});

it('should return a firstName with at least 1 accented character', () => {
const result = randFirstName({
...options,
withAccents: true,
});

expect(result.match(specialCharRegex)).toBeTruthy();
expect(data.withAccents.male.includes(result)).toBe(true);
});

it('should return a firstName with only non-accented characters', () => {
const result = randFirstName({
...options,
withAccents: false,
});

expect(result.match(specialCharRegex)).toBeFalsy();
expect(data.withoutAccents.male.includes(result)).toBe(true);
});
});
});
});

0 comments on commit e353b10

Please sign in to comment.