aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Narożnik <[email protected]>2022-02-01 20:19:35 +0100
committerGitHub <[email protected]>2022-02-01 20:19:35 +0100
commitb9c9f14d8e89426b261c2168cbbf4c643fa452fc (patch)
treeb918b751ea36176e2adcfa8e1a3803208b42e763
parent933d44aa6f101fd855d9cbeec2f051d656402b25 (diff)
downloadfaker-b9c9f14d8e89426b261c2168cbbf4c643fa452fc.tar.xz
faker-b9c9f14d8e89426b261c2168cbbf4c643fa452fc.zip
test: rewrite music tests (#383)
-rw-r--r--test/music.spec.ts68
1 files changed, 62 insertions, 6 deletions
diff --git a/test/music.spec.ts b/test/music.spec.ts
index b4983e6f..16660bbb 100644
--- a/test/music.spec.ts
+++ b/test/music.spec.ts
@@ -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();
+ expect(typeof genre).toBe('string');
+ expect(faker.definitions.music.genre).toContain(genre);
+ });
+ });
+ }
});
});