Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 235 additions & 24 deletions __tests__/Date/wtf.unit.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SRC: https://jsdate.wtf/
describe('Date', () => {
'use strict'

let oDate, dateString, dateValue, milliseconds

// 1 of 28
Expand All @@ -13,12 +15,11 @@ describe('Date', () => {
expect(dateString).not.toEqual('1970-01-01T00:00:00.000Z')
})

// FIXME? it matches in CI, but not in my local.
// Is it because I am on GMT-6?
xit('interprets "0" as the year 2000, not as a timestamp!', () => {
it('interprets "0" as the year 2000, not as a timestamp! parsing it as "2000-01-01T06:00:00.000"', () => {
// The string "0" is interpreted as the year 2000, not as a timestamp!
expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z') // According to https://jsdate.wtf
expect(dateString).toEqual('2000-01-01T06:00:00.000Z')
// expect(dateString).toEqual('2000-01-01T06:00:00.000Z')
const expectedDate = new Date('2000-01-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand Down Expand Up @@ -77,6 +78,10 @@ describe('Date', () => {
expect(dateValue).toBeNaN()
})

it('is still _.isDate() tho', () => {
expect(_.isDate(oDate)).toBe(true)
})

// 5 of 28
describe('.getTime()', () => {
beforeEach(() => {
Expand Down Expand Up @@ -144,12 +149,12 @@ describe('Date', () => {
expect(dateString).not.toEqual('0001-01-01T00:00:00.000Z')
})

// FIXME? it matches in CI, but not in my local.
// Is it because I am on GMT-6?
xit('equals to "2001-01-01T00:00:00.000Z"', () => {
it('equals to "2001-01-01T00:00:00.000"', () => {
// Unlike "0", "1" is interpreted as a month,
// and the year defaults to 2001 for some reason.
expect(dateString).toEqual('2001-01-01T00:00:00.000Z')
// expect(dateString).toEqual('2001-01-01T00:00:00.000Z')
const expectedDate = new Date('2001-01-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand All @@ -168,8 +173,10 @@ describe('Date', () => {
expect(dateString).not.toEqual('2001-01-02T00:00:00.000Z')
})

xit('equals "2001-02-01T00:00:00.000Z"', () => {
expect(dateString).toEqual('2001-02-01T00:00:00.000Z')
it('equals "2001-02-01T00:00:00.000"', () => {
// expect(dateString).toEqual('2001-02-01T00:00:00.000Z')
const expectedDate = new Date('2001-02-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand All @@ -188,9 +195,11 @@ describe('Date', () => {
expect(dateString).not.toEqual('2001-01-12T00:00:00.000Z')
})

xit('equals "2001-12-01T00:00:00.000Z"', () => {
it('equals "2001-12-01T00:00:00.000"', () => {
// Also works for December.
expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
// expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
const expectedDate = new Date('2001-12-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand Down Expand Up @@ -257,10 +266,12 @@ describe('Date', () => {
expect(dateString).not.toEqual('2012-01-01T00:00:00.000Z')
})

xit('equals "2001-12-01T00:00:00.000Z"', () => {
it('equals "2001-12-01T00:00:00.000"', () => {
// "12.1" is interpreted as the date December 1st,
// and as before for dates with no year the default is 2001 because of course.
expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
// expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
const expectedDate = new Date('2001-12-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand Down Expand Up @@ -299,9 +310,11 @@ describe('Date', () => {
expect(dateString).not.toEqual('2001-01-01T00:00:00.000Z')
})

xit('ignores the "-", interpreting it like "12.1", resulting in "2001-12-01T00:00:00.000Z"', () => {
it('ignores the "-", interpreting it like "12.1", resulting in "2001-12-01T00:00:00.000"', () => {
// The dash here is ignored, so this is interpreted the same as "12.1".
expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
// expect(dateString).toEqual('2001-12-01T00:00:00.000Z')
const expectedDate = new Date('2001-12-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand All @@ -316,10 +329,12 @@ describe('Date', () => {
expect(dateString).not.toEqual('1970-01-01T00:00:01.000Z')
})

xit('ignores leading text. Finding "1" and parsing it as January. Resulting in "2001-01-01T00:00:00.000Z"', () => {
it('ignores leading text. Finding "1" and parsing it as January. Resulting in "2001-01-01T00:00:00.000"', () => {
// Leading text is always ignored!
// It finds the "1" and parses it as the month January.
expect(dateString).toEqual('2001-01-01T00:00:00.000Z')
// expect(dateString).toEqual('2001-01-01T00:00:00.000Z')
const expectedDate = new Date('2001-01-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

Expand Down Expand Up @@ -349,6 +364,9 @@ describe('Date', () => {
// 19 of 28
describe('new Date("maybe 1")', () => {
beforeEach(() => {
// "may" in "maybe" is parsed as the month May!
// And for some reason this expression cares about your local timezone,
// which happens to be BST for me right now.
oDate = new Date('maybe 1')
dateString = oDate.toISOString()
})
Expand All @@ -362,11 +380,204 @@ describe('Date', () => {
expect(dateString).not.toEqual('2001-01-01T00:00:00.000Z')
})

xit('parses "maybe" as "may"! resulting in "2001-05-01T00:00:00.000Z"', () => {
// "may" in "maybe" is parsed as the month May!
// And for some reason this expression cares about your local timezone,
// which happens to be BST for me right now.
expect(dateString).toEqual('2001-05-01T00:00:00.000Z')
it('parses "maybe" as "may"! resulting in "2001-05-01T00:00:00.000"', () => {
// expect(dateString).toEqual('2001-05-01T00:00:00.000Z')
const expectedDate = new Date('2001-05-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

// 20 of 28
describe('new Date("fourth of may 2010")', () => {
beforeEach(() => {
// "fourth of" is ignored,
// this is just parsing "may 2010"
// and again local timezone is important.
oDate = new Date('fourth of may 2010')
dateString = oDate.toISOString()
})

// Works only in non-UTC timezones.
xit('does NOT equal "2010-05-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-05-01T00:00:00.000Z')
})

it('does NOT equal "2010-05-04T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-05-04T00:00:00.000Z')
})

it('ignores "fourth of", parsing "may 2010" as "2010-05-01T00:00:00.000"', () => {
// expect(dateString).toEqual('2010-05-01T00:00:00.000Z')
const expectedDate = new Date('2010-05-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

// 21 of 28
describe('new Date("May 4 UTC")', () => {
beforeEach(() => {
// UTC is correctly parsed as a timezone.
oDate = new Date('May 4 UTC')
dateString = oDate.toISOString()
})

it('does NOT equal "2010-04-30T23:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-04-30T23:00:00.000Z')
})

it('does NOT equal "2010-05-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-05-01T00:00:00.000Z')
})

it('parses UTC as "2001-05-04T00:00:00.000Z"', () => {
expect(dateString).toEqual('2001-05-04T00:00:00.000Z')
})
})

// 22 of 28
describe('new Date("May 4 UTC+1")', () => {
beforeEach(() => {
// You can add modifiers to timezones and it works as you would expect.
oDate = new Date('May 4 UTC+1')
dateString = oDate.toISOString()
})

it('does NOT equal "2001-05-04T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2001-05-04T00:00:00.000Z')
})

it('does NOT equal "2010-05-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-05-01T00:00:00.000Z')
})

it('parses UTC+1 as "2001-05-04T00:00:00.000", resulting in "2001-05-03T23:00:00.000Z"', () => {
// 05-04T00 @ UTC+1 is 1 hr ahead: 05-03T23 @ UTC
expect(dateString).toEqual('2001-05-03T23:00:00.000Z')
})
})

// 23 of 28
describe('new Date("May 4 UTC+1:59")', () => {
beforeEach(() => {
// It also supports minutes!
oDate = new Date('May 4 UTC+1:59')
dateString = oDate.toISOString()
})

it('does NOT equal "2001-05-04T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2001-05-04T00:00:00.000Z')
})

it('parses UTC+1:59 as "2001-05-04T00:00:00.000", resulting in "2001-05-03T22:01:00.000Z"', () => {
expect(dateString).toEqual('2001-05-03T22:01:00.000Z')
})
})

// 24 of 28
describe('new Date("May 4 UTC+1:60")', () => {
beforeEach(() => {
// Until it doesn't!
// 60 is being parsed as the year here,
// UTC+1 is the timezone.
oDate = new Date('May 4 UTC+1:60')
dateString = oDate.toISOString()
})

it('does NOT equal "2001-05-04T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2001-05-04T00:00:00.000Z')
})

it('does NOT equal "2001-05-03T22:00:00.000Z"', () => {
expect(dateString).not.toEqual('2001-05-03T22:00:00.000Z')
})

it('parses UTC+1:60 as "UTC+1" AND "year 60"!, resulting in "1960-05-03T23:00:00.000Z"', () => {
expect(dateString).toEqual('1960-05-03T23:00:00.000Z')
})
})

// 25 of 28
describe('new Date("1990 2010")', () => {
beforeEach(() => {
// No tricks here, just a plain ol' Invalid Date.
oDate = new Date('1990 2010')
dateString = oDate.toTimeString()
})

describe('.toTimeString()', () => {
it('equals "Invalid Date"', () => {
expect(dateString).toEqual('Invalid Date')
})
})

describe('.toISOString()', () => {
it('throws', () => {
expect(() => oDate.toISOString()).toThrow()
})
})
})

// 26 of 28
describe('new Date("1990 (2010)")', () => {
beforeEach(() => {
// For some reason, parenthesised text is ignored.
oDate = new Date('1990 (2010)')
dateString = oDate.toISOString()
})

it('does NOT equal "2000-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z')
})

it('does NOT equal "2010-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2010-01-01T00:00:00.000Z')
})

it('ignores text in parentheses, parsing this as "1990", resulting in "1990-01-01T00:00:00.000"', () => {
// expect(dateString).toEqual('1990-01-01T00:00:00.000Z')
const expectedDate = new Date('1990-01-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

// 27 of 28
describe('new Date("(1990) 2010")', () => {
beforeEach(() => {
// No matter where it is.
oDate = new Date('(1990) 2010')
dateString = oDate.toISOString()
})

it('does NOT equal "1990-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('1990-01-01T00:00:00.000Z')
})

it('does NOT equal "2000-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z')
})

it('ignores text in parentheses, parsing this as "2010", resulting in "2010-01-01T00:00:00.000"', () => {
// expect(dateString).toEqual('2010-01-01T00:00:00.000Z')
const expectedDate = new Date('2010-01-01T00:00:00.000')
expect(oDate.getTime()).toEqual(expectedDate.getTime())
})
})

// 28 of 28
describe('new Date(-[])', () => {
beforeEach(() => {
// -[] is coerced to 0,
// which is interpreted as milliseconds since the Unix epoch (Jan 1, 1970).
oDate = new Date(-[])
dateString = oDate.toISOString()
})

it('does NOT equal "2000-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z')
})

it('coerces -[] as 0, parsing it to "1970-01-01T00:00:00.000Z"', () => {
expect(dateString).toEqual('1970-01-01T00:00:00.000Z')
})
})
})
2 changes: 1 addition & 1 deletion __tests__/NaN/NaN.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('NaN', () => {

// except
it("is typeof 'number'", () => {
expect(typeof (NaN)).toBe('number') // [N]ot[a][N]umber >is< a number o.0
expect(typeof (NaN)).toBe('number') // [N]ot[a][N]umber >is< ALSO a number o.0
})
})

Expand Down
8 changes: 5 additions & 3 deletions __tests__/nothing/undefined.unit.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
describe('undefined', () => {
'use strict'

it("is typeof 'undefined", () => {
it("is typeof 'undefined'", () => {
expect(typeof (undefined)).toEqual('undefined')
})

describe('Number', () => {
it('isNaN', () => {
expect(isNaN(undefined)).toBe(true)
describe('isNaN(undefined)', () => {
it('is', () => {
expect(isNaN(undefined)).toBe(true)
})
})
})

Expand Down