Validating Constructor Type Checking in Day.js
This test suite validates core constructor functionality and type checking in Day.js, focusing on instance verification and object type detection. The tests ensure proper instance creation and reliable object type validation across different Day.js versions.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
iamkun/dayjs
test/constructor.test.js
import MockDate from 'mockdate'
import dayjs from '../src'
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
it('supports instanceof dayjs', () => {
expect(dayjs() instanceof dayjs).toBeTruthy()
})
it('$isDayjsObject', () => {
const mockOtherVersionDayjsObj = {
$isDayjsObject: true
}
expect(dayjs.isDayjs(mockOtherVersionDayjsObj)).toBeTruthy()
})
it('does not break isDayjs', () => {
expect(dayjs.isDayjs(dayjs())).toBeTruthy()
expect(dayjs.isDayjs(new Date())).toBeFalsy()
})