Skip to content

Commit

Permalink
chore(test): Add locale to test description (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Jan 23, 2022
1 parent 74204a0 commit 6ba72a4
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions test/all_functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function isTestableMethod(mod: string) {
function both(
pred1: (meth: string) => boolean,
pred2: (meth: string) => boolean
) {
): (meth: string) => boolean {
return (value) => pred1(value) && pred2(value);
}

// Basic smoke tests to make sure each method is at least implemented and returns a value.

function modulesList() {
function modulesList(): { [module: string]: string[] } {
const modules = Object.keys(faker)
.filter(isTestableModule)
.reduce((result, mod) => {
Expand All @@ -54,22 +54,24 @@ const modules = modulesList();

describe('functional tests', () => {
for (const locale in faker.locales) {
faker.locale = locale;
Object.keys(modules).forEach((module) => {
describe(module, () => {
// if there is nothing to test, create a dummy test so the test runner doesn't complain
if (Object.keys(modules[module]).length === 0) {
it.todo(`${module} was empty`);
}
describe(locale, () => {
faker.locale = locale;
Object.keys(modules).forEach((module) => {
describe(module, () => {
// if there is nothing to test, create a dummy test so the test runner doesn't complain
if (Object.keys(modules[module]).length === 0) {
it.todo(`${module} was empty`);
}

modules[module].forEach((meth) => {
it(meth + '()', () => {
const result = faker[module][meth]();
if (meth === 'boolean') {
expect(typeof result).toBe('boolean');
} else {
expect(result).toBeTruthy();
}
modules[module].forEach((meth) => {
it(meth + '()', () => {
const result = faker[module][meth]();
if (meth === 'boolean') {
expect(typeof result).toBe('boolean');
} else {
expect(result).toBeTruthy();
}
});
});
});
});
Expand All @@ -79,26 +81,28 @@ describe('functional tests', () => {

describe('faker.fake functional tests', () => {
for (const locale in faker.locales) {
faker.locale = locale;
faker.seed(1);
Object.keys(modules).forEach((module) => {
describe(module, () => {
// if there is nothing to test, create a dummy test so the test runner doesn't complain
if (Object.keys(modules[module]).length === 0) {
it.todo(`${module} was empty`);
}
describe(locale, () => {
faker.locale = locale;
faker.seed(1);
Object.keys(modules).forEach((module) => {
describe(module, () => {
// if there is nothing to test, create a dummy test so the test runner doesn't complain
if (Object.keys(modules[module]).length === 0) {
it.todo(`${module} was empty`);
}

modules[module].forEach((meth) => {
it(meth + '()', () => {
const result = faker.fake('{{' + module + '.' + meth + '}}');
// just make sure any result is returned
// an undefined result usually means an error
expect(result).toBeDefined();
// if (meth === 'boolean') {
// expect(typeof result).toBe('boolean');
// } else {
// expect(result).toBeTruthy();
// }
modules[module].forEach((meth) => {
it(meth + '()', () => {
const result = faker.fake('{{' + module + '.' + meth + '}}');
// just make sure any result is returned
// an undefined result usually means an error
expect(result).toBeDefined();
// if (meth === 'boolean') {
// expect(typeof result).toBe('boolean');
// } else {
// expect(result).toBeTruthy();
// }
});
});
});
});
Expand Down

0 comments on commit 6ba72a4

Please sign in to comment.