diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/time.spec.ts | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test/time.spec.ts b/test/time.spec.ts index 1146bb08..90d4d2c4 100644 --- a/test/time.spec.ts +++ b/test/time.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { faker } from '../src'; const seededRuns = [ @@ -56,23 +56,67 @@ describe('time', () => { 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 spy = vi.spyOn(console, 'warn'); + const date = faker.time.recent(); expect(date).toBeTypeOf('number'); + + expect(spy).toHaveBeenCalledWith( + `Deprecation Warning: faker.time.recent() is deprecated. Use the native \`new Date()\` and call the function you want on it. + abbr => toLocaleTimeString() + wide => toTimeString() + unix => getTime() +` + ); + spy.mockRestore(); }); it('should return the recent timestamp in full time string format', () => { + const spy = vi.spyOn(console, 'warn'); + const date = faker.time.recent('wide'); expect(date).toBeTypeOf('string'); + + expect(spy).toHaveBeenCalledWith( + `Deprecation Warning: faker.time.recent() is deprecated. Use the native \`new Date()\` and call the function you want on it. + abbr => toLocaleTimeString() + wide => toTimeString() + unix => getTime() +` + ); + spy.mockRestore(); }); it('should return the recent timestamp in abbreviated string format', () => { + const spy = vi.spyOn(console, 'warn'); + const date = faker.time.recent('abbr'); expect(date).toBeTypeOf('string'); + + expect(spy).toHaveBeenCalledWith( + `Deprecation Warning: faker.time.recent() is deprecated. Use the native \`new Date()\` and call the function you want on it. + abbr => toLocaleTimeString() + wide => toTimeString() + unix => getTime() +` + ); + spy.mockRestore(); }); it('should return the recent timestamp in unix time format', () => { + const spy = vi.spyOn(console, 'warn'); + const date = faker.time.recent('unix'); expect(date).toBeTypeOf('number'); + + expect(spy).toHaveBeenCalledWith( + `Deprecation Warning: faker.time.recent() is deprecated. Use the native \`new Date()\` and call the function you want on it. + abbr => toLocaleTimeString() + wide => toTimeString() + unix => getTime() +` + ); + spy.mockRestore(); }); }); } |
