Skip to content

Commit

Permalink
test: update to use seededTests factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Aug 13, 2022
1 parent 433c1e5 commit 91d943c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
13 changes: 13 additions & 0 deletions test/__snapshots__/zodiac.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Vitest Snapshot v1

exports[`zodiac > 42 > sign > noArgs 1`] = `"Gemini"`;

exports[`zodiac > 42 > sign > with birthdate 1`] = `"Aquarius"`;

exports[`zodiac > 1211 > sign > noArgs 1`] = `"Capricorn"`;

exports[`zodiac > 1211 > sign > with birthdate 1`] = `"Aquarius"`;

exports[`zodiac > 1337 > sign > noArgs 1`] = `"Taurus"`;

exports[`zodiac > 1337 > sign > with birthdate 1`] = `"Aquarius"`;
43 changes: 5 additions & 38 deletions test/zodiac.spec.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import type { Zodiac } from '../src/modules/zodiac';
import type { MethodsOf } from '../src/utils/types';

const seededRuns = [
{
seed: 42,
expectations: {
sign: 'Gemini',
},
},
{
seed: 1337,
expectations: {
sign: 'Taurus',
},
},
{
seed: 1211,
expectations: {
sign: 'Capricorn',
},
},
];
import { seededTests } from './support/seededRuns';

const NON_SEEDED_BASED_RUN = 5;

const functionNames: MethodsOf<Zodiac> = ['sign'];

const arrayOfSigns = Object.values(faker.definitions.zodiac.sign);

describe('zodiac', () => {
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.zodiac[functionName]();

expect(actual).toBeTypeOf('string');
expect(actual).toEqual(expectations[functionName]);
});
}
seededTests(faker, 'zodiac', (t) => {
t.describe('sign', (t) => {
t.it('noArgs').it('with birthdate', new Date(1974, 12, 34));
});
}
});

describe(`random seeded tests for seed ${JSON.stringify(
faker.seed()
Expand Down

0 comments on commit 91d943c

Please sign in to comment.