-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update devHelper add warning "passing Year as a Number will be p…
…arsed as a Unix timestamp" (#1315)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import devHelper from '../../src/plugin/devHelper' | ||
|
||
dayjs.extend(devHelper) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
global.console.warn = jest.genMockFunction() | ||
|
||
|
||
it('Warning: passing Year as a Number will be parsed as a Unix timestamp', () => { | ||
const consoleSpy = jest.spyOn(console, 'warn') | ||
dayjs(2020) | ||
expect(consoleSpy).toHaveBeenCalledWith('Guessing you may want to parse the Year 2020, you should pass it as a String 2020, not a Number. Otherwise, 2020 will be treated as a Unix timestamp') | ||
}) | ||
|
||
it('Warning Passing Unix timestamp as a String not Number', () => { | ||
const consoleSpy = jest.spyOn(console, 'warn') | ||
dayjs('1231231231231') | ||
expect(consoleSpy).toHaveBeenCalledWith('To parse a Unix timestamp like 1231231231231, you should pass it as a Number. https://day.js.org/docs/en/parse/unix-timestamp-milliseconds') | ||
}) | ||
|
||
it('Warning Enable customParseFormat plugin while passing the second format parameter', () => { | ||
const consoleSpy = jest.spyOn(console, 'warn') | ||
dayjs('2020', 'YYYY') | ||
expect(consoleSpy).toHaveBeenCalledWith('To parse a date-time string like 2020 using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format') | ||
}) |