diff options
| author | Shinigami <[email protected]> | 2022-03-25 16:45:16 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-25 16:45:16 +0100 |
| commit | ba3c62fca76fe2dc9fd1c8c9292c5333bf2c10a7 (patch) | |
| tree | a03fd86057314b26229cd628bdbeb1921e46d710 /test | |
| parent | 3252c7ea0421ead864fd41f4239e1b80f22c29bf (diff) | |
| download | faker-ba3c62fca76fe2dc9fd1c8c9292c5333bf2c10a7.tar.xz faker-ba3c62fca76fe2dc9fd1c8c9292c5333bf2c10a7.zip | |
refactor: deprecate time.recent (#661)
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(); }); }); } |
