Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rewrite hacker tests #386

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions test/hacker.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { faker } from '../dist/cjs';

const seededRuns = [
{
seed: 42,
expectations: {
abbreviation: {
noArgs: 'PCI',
},
adjective: {
noArgs: 'cross-platform',
},
noun: {
noArgs: 'array',
},
verb: {
noArgs: 'navigate',
},
ingverb: {
noArgs: 'copying',
},
phrase: {
noArgs:
'Try to transmit the SAS microchip, maybe it will quantify the mobile monitor!',
},
},
},
{
seed: 1337,
expectations: {
abbreviation: {
noArgs: 'AGP',
},
adjective: {
noArgs: 'open-source',
},
noun: {
noArgs: 'port',
},
verb: {
noArgs: 'compress',
},
ingverb: {
noArgs: 'compressing',
},
phrase: {
noArgs:
'Try to generate the COM program, maybe it will connect the back-end port!',
},
},
},
{
seed: 1211,
expectations: {
abbreviation: {
noArgs: 'JSON',
},
adjective: {
noArgs: 'solid state',
},
noun: {
noArgs: 'capacitor',
},
verb: {
noArgs: 'reboot',
},
ingverb: {
noArgs: 'programming',
},
phrase: {
noArgs:
"I'll back up the neural RSS program, that should panel the SCSI matrix!",
},
},
},
];

const NON_SEEDED_BASED_RUN = 5;

const functionNames = [
'abbreviation',
'adjective',
'noun',
'verb',
'ingverb',
'phrase',
];

describe('name', () => {
afterEach(() => {
faker.locale = 'en';
});

for (const { seed, expectations } of seededRuns) {
describe(`seed: ${seed}`, () => {
for (const functionName of functionNames) {
it(`${functionName}()`, () => {
faker.seed(seed);

const actual = faker.hacker[functionName]();
expect(actual).toEqual(expectations[functionName].noArgs);
});
}
});
}

// Create and log-back the seed for debug purposes
faker.seed(Math.ceil(Math.random() * 1_000_000_000));

describe(`random seeded tests for seed ${faker.seedValue}`, () => {
for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) {
describe('abbreviation()', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random abbreviation from array', () => {
const abbreviation = faker.hacker.abbreviation();

expect(typeof abbreviation).toBe('string');
expect(abbreviation.length).greaterThan(0);
expect(faker.definitions.hacker.abbreviation).toContain(abbreviation);
});
});

describe('adjective', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random adjective from array', () => {
const adjective = faker.hacker.adjective();

expect(typeof adjective).toBe('string');
expect(adjective.length).greaterThan(0);
expect(faker.definitions.hacker.adjective).toContain(adjective);
});
});

describe('noun', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random noun from array', () => {
const noun = faker.hacker.noun();

expect(typeof noun).toBe('string');
expect(noun.length).greaterThan(0);
expect(faker.definitions.hacker.noun).toContain(noun);
});
});

describe('verb', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random verb from array', () => {
const verb = faker.hacker.verb();

expect(typeof verb).toBe('string');
expect(verb.length).greaterThan(0);
expect(faker.definitions.hacker.verb).toContain(verb);
});
});

describe('ingverb', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random ingverb from array', () => {
const ingverb = faker.hacker.ingverb();

expect(typeof ingverb).toBe('string');
expect(ingverb.length).greaterThan(0);
expect(faker.definitions.hacker.ingverb).toContain(ingverb);
});
});

describe('phrase', () => {
beforeEach(() => {
faker.locale = 'en';
});

it('should return a random phrase from array', () => {
const phrase = faker.hacker.phrase();

expect(typeof phrase).toBe('string');
expect(phrase.length).greaterThan(0);
});
});
}
});
});