Testing isYesterday Date Validation in dayjs
This test suite validates the isYesterday plugin functionality in Day.js, focusing on date comparison operations. The tests ensure accurate identification of dates that fall on the previous day using the isYesterday() method with proper date mocking.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
iamkun/dayjs
test/plugin/isYesterday.test.js
import MockDate from 'mockdate'
import dayjs from '../../src'
import isYesterday from '../../src/plugin/isYesterday'
dayjs.extend(isYesterday)
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
it('is yesterday', () => {
expect(dayjs().subtract(1, 'day').isYesterday()).toBeTruthy()
expect(dayjs('2017-01-01').isYesterday()).toBeFalsy()
})