-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
046d598
commit 2b00137
Showing
1 changed file
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,78 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { faker } from '../dist/cjs'; | ||
|
||
faker.seed(1234); | ||
const seededRuns = [ | ||
{ | ||
seed: 42, | ||
expectations: { | ||
recent: { | ||
noArgs: 'number', | ||
}, | ||
}, | ||
}, | ||
{ | ||
seed: 1337, | ||
expectations: { | ||
recent: { | ||
noArgs: 'number', | ||
}, | ||
}, | ||
}, | ||
{ | ||
seed: 1211, | ||
expectations: { | ||
recent: { | ||
noArgs: 'number', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const NON_SEEDED_BASED_RUN = 5; | ||
|
||
const functionNames = ['recent']; | ||
|
||
describe('time', () => { | ||
describe('recent()', () => { | ||
it('returns the recent timestamp in Unix time format', () => { | ||
const date = faker.time.recent(); | ||
expect(typeof date).toBe('number'); | ||
}); | ||
// TODO @Shinigami92 2022-02-04: Results are not seeded yet | ||
for (const { seed, expectations } of seededRuns) { | ||
describe(`seed: ${seed}`, () => { | ||
for (const functionName of functionNames) { | ||
it(`${functionName}()`, () => { | ||
faker.seed(seed); | ||
|
||
it('returns the recent timestamp in full time string format', () => { | ||
const date = faker.time.recent('wide'); | ||
expect(typeof date).toBe('string'); | ||
const actual = faker.time[functionName](); | ||
expect(typeof actual).toEqual(expectations[functionName].noArgs); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
it('returns the recent timestamp in abbreviated string format', () => { | ||
const date = faker.time.recent('abbr'); | ||
expect(typeof date).toBe('string'); | ||
}); | ||
// 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('recent()', () => { | ||
it('should return the recent timestamp in unix time format by default', () => { | ||
const date = faker.time.recent(); | ||
expect(typeof date).toBe('number'); | ||
}); | ||
|
||
it('should return the recent timestamp in full time string format', () => { | ||
const date = faker.time.recent('wide'); | ||
expect(typeof date).toBe('string'); | ||
}); | ||
|
||
it('should return the recent timestamp in abbreviated string format', () => { | ||
const date = faker.time.recent('abbr'); | ||
expect(typeof date).toBe('string'); | ||
}); | ||
|
||
it('should return the recent timestamp in unix time format', () => { | ||
const date = faker.time.recent('unix'); | ||
expect(typeof date).toBe('number'); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); |