Skip to content

Commit

Permalink
test: add dst test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Jan 11, 2019
1 parent 8580991 commit 0d7ed9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"types": "index.d.ts",
"scripts": {
"test": "jest",
"test-dst": "TZ=Pacific/Auckland npm run dst-test && TZ=Europe/London npm run dst-test && npm run dst-test",
"dst-test": "jest test/dst.test --coverage=false",
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
"build": "cross-env BABEL_ENV=build node build && npm run size",
"sauce": "npx karma start karma.sauce.conf.js",
Expand Down
21 changes: 21 additions & 0 deletions test/dst.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../src'

beforeEach(() => {
MockDate.set(new Date())
})

afterEach(() => {
MockDate.reset()
})

it('Add Time days (DST)', () => {
// change timezone before running test
// New Zealand (-720)
expect(dayjs('2018-04-01').add(1, 'd').format()).toBe(moment('2018-04-01').add(1, 'd').format())
expect(dayjs('2018-03-28').add(1, 'w').format()).toBe(moment('2018-03-28').add(1, 'w').format())
// London (-60)
expect(dayjs('2018-10-28').add(1, 'd').format()).toBe(moment('2018-10-28').add(1, 'd').format())
expect(dayjs('2018-10-26').add(1, 'w').format()).toBe(moment('2018-10-26').add(1, 'w').format())
})
10 changes: 0 additions & 10 deletions test/manipulate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,3 @@ it('Add Time days', () => {
it('Subtract Time days', () => {
expect(dayjs().subtract(1, 'days').valueOf()).toBe(moment().subtract(1, 'days').valueOf())
})

it('Add Time days (DST)', () => {
// change timezone before running test
// New Zealand (-720)
expect(dayjs('2018-04-01').add(1, 'd').format()).toBe(moment('2018-04-01').add(1, 'd').format())
expect(dayjs('2018-03-28').add(1, 'w').format()).toBe(moment('2018-03-28').add(1, 'w').format())
// London (-60)
expect(dayjs('2018-10-28').add(1, 'd').format()).toBe(moment('2018-10-28').add(1, 'd').format())
expect(dayjs('2018-10-26').add(1, 'w').format()).toBe(moment('2018-10-26').add(1, 'w').format())
})

0 comments on commit 0d7ed9e

Please sign in to comment.