Testing isMoment Plugin Type Validation in dayjs
This test suite validates the isMoment plugin functionality in Day.js, ensuring proper type checking for dayjs objects. The tests verify the plugin’s ability to distinguish between dayjs instances and regular Date objects, with mock date handling for consistent testing.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
iamkun/dayjs
test/plugin/isMoment.test.js
import MockDate from 'mockdate'
import dayjs from '../../src'
import isMoment from '../../src/plugin/isMoment'
dayjs.extend(isMoment)
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
it('IsLeapYear', () => {
expect(dayjs.isMoment(dayjs())).toBe(true)
expect(dayjs.isMoment(new Date())).toBe(false)
})