aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-02-01 19:26:04 +0100
committerGitHub <[email protected]>2022-02-01 19:26:04 +0100
commite27d8d97d085d4bb0cb06ed68077cff953436f30 (patch)
tree8e4f38955b46654d64502a880f8fe0d9f6923549 /test
parentdf48704c818a1addb8c32140f12e592e243f4e6d (diff)
downloadfaker-e27d8d97d085d4bb0cb06ed68077cff953436f30.tar.xz
faker-e27d8d97d085d4bb0cb06ed68077cff953436f30.zip
test: rewrite hacker tests (#386)
Diffstat (limited to 'test')
-rw-r--r--test/hacker.spec.ts197
1 files changed, 197 insertions, 0 deletions
diff --git a/test/hacker.spec.ts b/test/hacker.spec.ts
new file mode 100644
index 00000000..d666b290
--- /dev/null
+++ b/test/hacker.spec.ts
@@ -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);
+ });
+ });
+ }
+ });
+});