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 music tests #383

Merged
merged 7 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
68 changes: 62 additions & 6 deletions test/music.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,70 @@
import { describe, expect, it } from 'vitest';
import { beforeEach, describe, expect, it } from 'vitest';
import { faker } from '../dist/cjs';

faker.seed(1234);
const seededRuns = [
{
seed: 42,
expectations: {
genre: {
noArgs: 'Country',
},
},
},
{
seed: 1337,
expectations: {
genre: {
noArgs: 'Folk',
},
},
},
{
seed: 1211,
expectations: {
genre: {
noArgs: 'Non Music',
},
},
},
];

const functionNames = ['genre'];

const NON_SEEDED_BASED_RUN = 5;

describe('music', () => {
describe('genre()', () => {
it('returns a genre', () => {
const genre = faker.music.genre();
beforeEach(() => {
faker.locale = 'en';
});

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

expect(genre).toBe('Electronic');
const actual = faker.music[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('genre()', () => {
it('should return a genre', () => {
const genre = faker.music.genre();

expect(genre).toBeTruthy();
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
expect(typeof genre).toBe('string');
expect(faker.definitions.music.genre).toContain(genre);
});
});
}
});
});