Skip to content

Commit

Permalink
test: add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Mar 7, 2019
1 parent 37ab09f commit c9916fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/index.js
Expand Up @@ -344,8 +344,7 @@ class Dayjs {
}

daysInMonth() {
// clone is for badMutable plugin
return this.clone().endOf(C.M).$D
return this.endOf(C.M).$D
}

$locale() { // get locale object
Expand Down
20 changes: 20 additions & 0 deletions src/plugin/badMutable/index.js
Expand Up @@ -29,5 +29,25 @@ export default (o, c) => { // locale needed later
this.$L = oldLocale.bind(this)(preset, object).$L
return this
}

const oldDaysInMonth = proto.daysInMonth
proto.daysInMonth = function () {
return oldDaysInMonth.bind(this.clone())()
}

const oldIsSame = proto.isSame
proto.isSame = function () {
return oldIsSame.bind(this.clone())()
}

const oldIsBefore = proto.isBefore
proto.isBefore = function () {
return oldIsBefore.bind(this.clone())()
}

const oldIsAfter = proto.isAfter
proto.isAfter = function () {
return oldIsAfter.bind(this.clone())()
}
}

11 changes: 11 additions & 0 deletions test/plugin/badMutable.test.js
Expand Up @@ -161,3 +161,14 @@ it('Locale', () => {
expect(d.locale()).toBe(m.locale())
expect(d.format(format)).toBe(m.format(format))
})

it('isAfter isBefore isSame', () => {
const d = dayjs()
const format = dayjs().format()
d.isSame(dayjs, 'year')
expect(d.format()).toBe(format)
d.isBefore(dayjs, 'hour')
expect(d.format()).toBe(format)
d.isAfter(dayjs, 'month')
expect(d.format()).toBe(format)
})

0 comments on commit c9916fe

Please sign in to comment.