diff --git a/package.json b/package.json index 86cf6fe..1879d34 100644 --- a/package.json +++ b/package.json @@ -29,23 +29,21 @@ "scripts": { "build": "npm run clean && tsc", "clean": "rimraf -rf lib", - "test": "cross-env NODE_ENV=test nyc mocha test/*.spec.ts --exit --timeout 10000", - "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", + "test": "jest", + "coverage": "jest && codecov", "prepublishOnly": "npm run build" }, "devDependencies": { "@types/chai": "^4.1.7", - "@types/mocha": "^5.2.5", + "@types/jest": "^23.3.12", "@types/node": "^10.9.4", - "chai": "^4.1.2", "codecov": "^3.1.0", "cross-env": "^5.2.0", "husky": "^1.2.1", - "mocha": "^5.2.0", + "jest": "^23.6.0", "moment": "^2.23.0", - "nyc": "^13.0.1", "rimraf": "^2.6.2", - "source-map-support": "^0.5.9", + "ts-jest": "^23.10.5", "ts-node": "^7.0.1", "tslint": "^5.10.0", "tslint-eslint-rules": "^5.3.1", @@ -60,20 +58,37 @@ "pre-commit": "npm test" } }, - "nyc": { - "check-coverage": true, - "include": [ - "src/*.ts" + "jest": { + "roots": [ + "test" ], - "extension": [ - ".ts" + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testRegex": "test/.*\\.spec\\.(ts|tsx)$", + "moduleDirectories": [ + "node_modules", + "src" ], - "require": [ - "ts-node/register", - "source-map-support/register" + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx" ], - "sourceMap": true, - "instrument": true + "coverageDirectory": "./coverage/", + "collectCoverage": true, + "collectCoverageFrom": [ + "src/**/*.{ts,tsx}" + ], + "coverageThreshold": { + "global": { + "branches": 80, + "functions": 90, + "lines": 90, + "statements": -10 + } + } }, "publishConfig": { "access": "public" diff --git a/test/add.spec.ts b/test/add.spec.ts index edb6379..5b03d4c 100644 --- a/test/add.spec.ts +++ b/test/add.spec.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import * as moment from 'moment'; import { Moment } from '../src'; @@ -9,177 +8,175 @@ describe('add', () => { it('year', () => { expect(momentjs(now).add(5, 'year').valueOf()) - .to.be.equal(moment(now).add(5, 'year').valueOf()); + .toBe(moment(now).add(5, 'year').valueOf()); }); it('month: 3', () => { expect(momentjs(now).add(3, 'month').valueOf()) - .to.be.equal(moment(now).add(3, 'month').valueOf()); + .toBe(moment(now).add(3, 'month').valueOf()); }); it('month: 18', () => { expect(momentjs(now).add(18, 'month').valueOf()) - .to.be.equal(moment(now).add(18, 'month').valueOf()); + .toBe(moment(now).add(18, 'month').valueOf()); }); it('month: 128', () => { expect(momentjs(now).add(128, 'month').valueOf()) - .to.be.equal(moment(now).add(128, 'month').valueOf()); + .toBe(moment(now).add(128, 'month').valueOf()); }); it('day: 1', () => { - console.log(momentjs(now).add(1, 'day').valueOf()); - console.log(moment(now).add(1, 'day').valueOf()); expect(momentjs(now).add(1, 'day').valueOf()) - .to.be.equal(moment(now).add(1, 'day').valueOf()); + .toBe(moment(now).add(1, 'day').valueOf()); }); it('day: 8', () => { expect(momentjs(now).add(8, 'day').valueOf()) - .to.be.equal(moment(now).add(8, 'day').valueOf()); + .toBe(moment(now).add(8, 'day').valueOf()); }); it('day: 88', () => { expect(momentjs(now).add(88, 'day').valueOf()) - .to.be.equal(moment(now).add(88, 'day').valueOf()); + .toBe(moment(now).add(88, 'day').valueOf()); }); it('day: 888', () => { expect(momentjs(now).add(888, 'day').valueOf()) - .to.be.equal(moment(now).add(888, 'day').valueOf()); + .toBe(moment(now).add(888, 'day').valueOf()); }); it('day: 8888', () => { expect(momentjs(now).add(8888, 'day').valueOf()) - .to.be.equal(moment(now).add(8888, 'day').valueOf()); + .toBe(moment(now).add(8888, 'day').valueOf()); }); it('hour: 1', () => { expect(momentjs(now).add(1, 'hour').valueOf()) - .to.be.equal(moment(now).add(1, 'hour').valueOf()); + .toBe(moment(now).add(1, 'hour').valueOf()); }); it('hour: 8', () => { expect(momentjs(now).add(8, 'hour').valueOf()) - .to.be.equal(moment(now).add(8, 'hour').valueOf()); + .toBe(moment(now).add(8, 'hour').valueOf()); }); it('hour: 88', () => { expect(momentjs(now).add(88, 'hour').valueOf()) - .to.be.equal(moment(now).add(88, 'hour').valueOf()); + .toBe(moment(now).add(88, 'hour').valueOf()); }); it('hour: 888', () => { expect(momentjs(now).add(888, 'hour').valueOf()) - .to.be.equal(moment(now).add(888, 'hour').valueOf()); + .toBe(moment(now).add(888, 'hour').valueOf()); }); it('hour: 8888', () => { expect(momentjs(now).add(8888, 'hour').valueOf()) - .to.be.equal(moment(now).add(8888, 'hour').valueOf()); + .toBe(moment(now).add(8888, 'hour').valueOf()); }); it('minute: 1', () => { expect(momentjs(now).add(1, 'minute').valueOf()) - .to.be.equal(moment(now).add(1, 'minute').valueOf()); + .toBe(moment(now).add(1, 'minute').valueOf()); }); it('minute: 8', () => { expect(momentjs(now).add(8, 'minute').valueOf()) - .to.be.equal(moment(now).add(8, 'minute').valueOf()); + .toBe(moment(now).add(8, 'minute').valueOf()); }); it('minute: 88', () => { expect(momentjs(now).add(88, 'minute').valueOf()) - .to.be.equal(moment(now).add(88, 'minute').valueOf()); + .toBe(moment(now).add(88, 'minute').valueOf()); }); it('minute: 888', () => { expect(momentjs(now).add(888, 'minute').valueOf()) - .to.be.equal(moment(now).add(888, 'minute').valueOf()); + .toBe(moment(now).add(888, 'minute').valueOf()); }); it('minute: 8888', () => { expect(momentjs(now).add(8888, 'minute').valueOf()) - .to.be.equal(moment(now).add(8888, 'minute').valueOf()); + .toBe(moment(now).add(8888, 'minute').valueOf()); }); it('second: 1', () => { expect(momentjs(now).add(1, 'second').valueOf()) - .to.be.equal(moment(now).add(1, 'second').valueOf()); + .toBe(moment(now).add(1, 'second').valueOf()); }); it('second: 8', () => { expect(momentjs(now).add(8, 'second').valueOf()) - .to.be.equal(moment(now).add(8, 'second').valueOf()); + .toBe(moment(now).add(8, 'second').valueOf()); }); it('second: 88', () => { expect(momentjs(now).add(88, 'second').valueOf()) - .to.be.equal(moment(now).add(88, 'second').valueOf()); + .toBe(moment(now).add(88, 'second').valueOf()); }); it('second: 888', () => { expect(momentjs(now).add(888, 'second').valueOf()) - .to.be.equal(moment(now).add(888, 'second').valueOf()); + .toBe(moment(now).add(888, 'second').valueOf()); }); it('second: 8888', () => { expect(momentjs(now).add(8888, 'second').valueOf()) - .to.be.equal(moment(now).add(8888, 'second').valueOf()); + .toBe(moment(now).add(8888, 'second').valueOf()); }); it('millisecond: 1', () => { expect(momentjs(now).add(1, 'millisecond').valueOf()) - .to.be.equal(moment(now).add(1, 'millisecond').valueOf()); + .toBe(moment(now).add(1, 'millisecond').valueOf()); }); it('millisecond: 8', () => { expect(momentjs(now).add(8, 'millisecond').valueOf()) - .to.be.equal(moment(now).add(8, 'millisecond').valueOf()); + .toBe(moment(now).add(8, 'millisecond').valueOf()); }); it('millisecond: 88', () => { expect(momentjs(now).add(88, 'millisecond').valueOf()) - .to.be.equal(moment(now).add(88, 'millisecond').valueOf()); + .toBe(moment(now).add(88, 'millisecond').valueOf()); }); it('millisecond: 888', () => { expect(momentjs(now).add(888, 'millisecond').valueOf()) - .to.be.equal(moment(now).add(888, 'millisecond').valueOf()); + .toBe(moment(now).add(888, 'millisecond').valueOf()); }); it('millisecond: 8888', () => { expect(momentjs(now).add(8888, 'millisecond').valueOf()) - .to.be.equal(moment(now).add(8888, 'millisecond').valueOf()); + .toBe(moment(now).add(8888, 'millisecond').valueOf()); }); it('week: 1', () => { expect(momentjs(now).add(1, 'week').valueOf()) - .to.be.equal(moment(now).add(1, 'week').valueOf()); + .toBe(moment(now).add(1, 'week').valueOf()); }); it('week: 8', () => { expect(momentjs(now).add(8, 'week').valueOf()) - .to.be.equal(moment(now).add(8, 'week').valueOf()); + .toBe(moment(now).add(8, 'week').valueOf()); }); it('week: 88', () => { expect(momentjs(now).add(88, 'week').valueOf()) - .to.be.equal(moment(now).add(88, 'week').valueOf()); + .toBe(moment(now).add(88, 'week').valueOf()); }); it('week: 888', () => { expect(momentjs(now).add(888, 'week').valueOf()) - .to.be.equal(moment(now).add(888, 'week').valueOf()); + .toBe(moment(now).add(888, 'week').valueOf()); }); it('week: 8888', () => { expect(momentjs(now).add(8888, 'week').valueOf()) - .to.be.equal(moment(now).add(8888, 'week').valueOf()); + .toBe(moment(now).add(8888, 'week').valueOf()); }); it('special: 20111031 + 1 month should be 20111130', () => { - expect(momentjs('20111031').add(1, 'month').valueOf()).to.be.equal(moment('20111031').add(1, 'month').valueOf()) + expect(momentjs('20111031').add(1, 'month').valueOf()).toBe(moment('20111031').add(1, 'month').valueOf()) }); }); diff --git a/test/endOf.spec.ts b/test/endOf.spec.ts index ed331f2..5a93440 100644 --- a/test/endOf.spec.ts +++ b/test/endOf.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { Moment } from '../src'; import { resolve } from '../src/utils'; @@ -13,7 +11,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('year').valueOf()) - .to.be.equal(+new Date(dates[0], 11, 31, 23, 59, 59, 999)); + .toBe(+new Date(dates[0], 11, 31, 23, 59, 59, 999)); }); it('month', () => { @@ -21,7 +19,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('month').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1] + 1, 0, 23, 59, 59, 999)); + .toBe(+new Date(dates[0], dates[1] + 1, 0, 23, 59, 59, 999)); }); it('day', () => { @@ -29,7 +27,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('day').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], 23, 59, 59, 999)); + .toBe(+new Date(dates[0], dates[1], dates[2], 23, 59, 59, 999)); }); it('week', () => { @@ -37,7 +35,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('week').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2] - resolve(date).week + 6, 23, 59, 59, 999)); + .toBe(+new Date(dates[0], dates[1], dates[2] - resolve(date).week + 6, 23, 59, 59, 999)); }); it('hour', () => { @@ -45,7 +43,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('hour').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], 59, 59, 999)); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3], 59, 59, 999)); }); it('minute', () => { @@ -53,7 +51,7 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('minute').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], 59, 999)); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], 59, 999)); }); it('second', () => { @@ -61,6 +59,6 @@ describe('endOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.endOf('second').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5], 999)); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5], 999)); }); }); diff --git a/test/format.spec.ts b/test/format.spec.ts index 7106e9d..e3c36ce 100644 --- a/test/format.spec.ts +++ b/test/format.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import * as moment from 'moment'; import { Moment, Locale } from '../src'; import { padStart, getZone } from '../src/utils'; @@ -14,59 +12,58 @@ describe('format', () => { it('default: YYYY-MM-DDTHH:mm:ssZ', () => { const mj = momentjs(); expect(mj.format()) - .to.be.equal(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())}T${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}${zone}`); + .toBe(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())}T${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}${zone}`); }); it('YYYY-MM-DD HH:mm:ss', () => { const mj = momentjs(); expect(mj.format('YYYY-MM-DD HH:mm:ss')) - .to.be.equal(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}`); + .toBe(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}`); }); it('YYYY/MM/DD HH:mm:ss', () => { const mj = momentjs(); expect(mj.format('YYYY/MM/DD HH:mm:ss')) - .to.be.equal(`${mj.year()}/${pad(mj.month() + 1)}/${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}`); + .toBe(`${mj.year()}/${pad(mj.month() + 1)}/${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}`); }); it('YYYY/MM/DD HH:mm:ss.SSS', () => { const mj = momentjs(); expect(mj.format('YYYY/MM/DD HH:mm:ss.SSS')) - .to.be.equal(`${mj.year()}/${pad(mj.month() + 1)}/${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}.${pad3(mj.milliSecond())}`); + .toBe(`${mj.year()}/${pad(mj.month() + 1)}/${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())}.${pad3(mj.milliSecond())}`); }); it('dddd D, MMMMM', () => { const mj = momentjs(); expect(mj.format('dddd D, MMMM')) - .to.be.equal(`${((mj as any).$locale as Locale).weekdays[mj.week()]} ${mj.day()}, ${((mj as any).$locale as Locale).months[mj.month()]}`); + .toBe(`${((mj as any).$locale as Locale).weekdays[mj.week()]} ${mj.day()}, ${((mj as any).$locale as Locale).months[mj.month()]}`); }); it('YYYY-MM-DD HH:mm:ss a', () => { const mj = momentjs(); expect(mj.format('YYYY-MM-DD HH:mm:ss a')) - .to.be.equal(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())} ${mj.hour() < 12 ? 'am' : 'pm'}`); + .toBe(`${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())} ${pad(mj.hour())}:${pad(mj.minute())}:${pad(mj.second())} ${mj.hour() < 12 ? 'am' : 'pm'}`); }); it('YYYY-MM-DD hh:mm:ss A', () => { const now = new Date(); const mj = momentjs(now); // expect(mj.format('YYYY-MM-DD hh:mm:ss A')) - // .to.be.equal( + // .toBe( // `${mj.year()}-${pad(mj.month() + 1)}-${pad(mj.day())}` + // ` ${pad(mj.hour() < 13 ? mj.hour() : mj.hour() - 12)}:${pad(mj.minute())}:${pad(mj.second())} ${mj.hour() < 12 ? 'AM' : 'PM'}` // ); - expect(mj.format('YYYY-MM-DD hh:mm:ss A')).to.be.equal(moment(now).format('YYYY-MM-DD hh:mm:ss A')); + expect(mj.format('YYYY-MM-DD hh:mm:ss A')).toBe(moment(now).format('YYYY-MM-DD hh:mm:ss A')); }); }); describe('moment', () => { it('Format empty string', () => { - console.log(momentjs().format(), moment().format()); - expect(momentjs().format()).to.be.equal(moment().format()); + expect(momentjs().format()).toBe(moment().format()); }); it('Format escaped string', () => { - expect(momentjs().format('YYYY [escaped] YYYY')).to.be.equal(moment().format('YYYY [escaped] YYYY')); + expect(momentjs().format('YYYY [escaped] YYYY')).toBe(moment().format('YYYY [escaped] YYYY')); }); }); }); diff --git a/test/index.spec.ts b/test/index.spec.ts index 78c5fc4..c4d9417 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import * as wmoment from 'moment'; import moment from '../src'; @@ -8,13 +6,13 @@ describe('@zcorky/moment', () => { const now = Date.now(); const i = moment(now).startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); const m = wmoment(now).startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); - expect(i).to.be.equal(m); + expect(i).toBe(m); }); it('moment', () => { const now = moment(); const i = moment(now).startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); const m = wmoment(now).startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); - expect(i).to.be.equal(m); + expect(i).toBe(m); }); }); diff --git a/test/minus.spec.ts b/test/minus.spec.ts index e460ab1..8edadd9 100644 --- a/test/minus.spec.ts +++ b/test/minus.spec.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import * as moment from 'moment'; import { Moment } from '../src'; @@ -9,171 +8,171 @@ describe('minus', () => { it('year', () => { expect(momentjs(now).minus(5, 'year').valueOf()) - .to.be.equal(moment(now).subtract(5, 'year').valueOf()); + .toBe(moment(now).subtract(5, 'year').valueOf()); }); it('month: 3', () => { expect(momentjs(now).minus(3, 'month').valueOf()) - .to.be.equal(moment(now).subtract(3, 'month').valueOf()); + .toBe(moment(now).subtract(3, 'month').valueOf()); }); it('month: 18', () => { expect(momentjs(now).minus(18, 'month').valueOf()) - .to.be.equal(moment(now).subtract(18, 'month').valueOf()); + .toBe(moment(now).subtract(18, 'month').valueOf()); }); it('month: 128', () => { expect(momentjs(now).minus(128, 'month').valueOf()) - .to.be.equal(moment(now).subtract(128, 'month').valueOf()); + .toBe(moment(now).subtract(128, 'month').valueOf()); }); it('day: 1', () => { expect(momentjs(now).minus(1, 'day').valueOf()) - .to.be.equal(moment(now).subtract(1, 'day').valueOf()); + .toBe(moment(now).subtract(1, 'day').valueOf()); }); it('day: 8', () => { expect(momentjs(now).minus(8, 'day').valueOf()) - .to.be.equal(moment(now).subtract(8, 'day').valueOf()); + .toBe(moment(now).subtract(8, 'day').valueOf()); }); it('day: 88', () => { expect(momentjs(now).minus(88, 'day').valueOf()) - .to.be.equal(moment(now).subtract(88, 'day').valueOf()); + .toBe(moment(now).subtract(88, 'day').valueOf()); }); it('day: 888', () => { expect(momentjs(now).minus(888, 'day').valueOf()) - .to.be.equal(moment(now).subtract(888, 'day').valueOf()); + .toBe(moment(now).subtract(888, 'day').valueOf()); }); it('day: 8888', () => { expect(momentjs(now).minus(8888, 'day').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'day').valueOf()); + .toBe(moment(now).subtract(8888, 'day').valueOf()); }); it('hour: 1', () => { expect(momentjs(now).minus(1, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(1, 'hour').valueOf()); + .toBe(moment(now).subtract(1, 'hour').valueOf()); }); it('hour: 8', () => { expect(momentjs(now).minus(8, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(8, 'hour').valueOf()); + .toBe(moment(now).subtract(8, 'hour').valueOf()); }); it('hour: 88', () => { expect(momentjs(now).minus(88, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(88, 'hour').valueOf()); + .toBe(moment(now).subtract(88, 'hour').valueOf()); }); it('hour: 888', () => { expect(momentjs(now).minus(888, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(888, 'hour').valueOf()); + .toBe(moment(now).subtract(888, 'hour').valueOf()); }); it('hour: 8888', () => { expect(momentjs(now).minus(8888, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'hour').valueOf()); + .toBe(moment(now).subtract(8888, 'hour').valueOf()); }); it('minute: 1', () => { expect(momentjs(now).minus(1, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(1, 'minute').valueOf()); + .toBe(moment(now).subtract(1, 'minute').valueOf()); }); it('minute: 8', () => { expect(momentjs(now).minus(8, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(8, 'minute').valueOf()); + .toBe(moment(now).subtract(8, 'minute').valueOf()); }); it('minute: 88', () => { expect(momentjs(now).minus(88, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(88, 'minute').valueOf()); + .toBe(moment(now).subtract(88, 'minute').valueOf()); }); it('minute: 888', () => { expect(momentjs(now).minus(888, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(888, 'minute').valueOf()); + .toBe(moment(now).subtract(888, 'minute').valueOf()); }); it('minute: 8888', () => { expect(momentjs(now).minus(8888, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'minute').valueOf()); + .toBe(moment(now).subtract(8888, 'minute').valueOf()); }); it('second: 1', () => { expect(momentjs(now).minus(1, 'second').valueOf()) - .to.be.equal(moment(now).subtract(1, 'second').valueOf()); + .toBe(moment(now).subtract(1, 'second').valueOf()); }); it('second: 8', () => { expect(momentjs(now).minus(8, 'second').valueOf()) - .to.be.equal(moment(now).subtract(8, 'second').valueOf()); + .toBe(moment(now).subtract(8, 'second').valueOf()); }); it('second: 88', () => { expect(momentjs(now).minus(88, 'second').valueOf()) - .to.be.equal(moment(now).subtract(88, 'second').valueOf()); + .toBe(moment(now).subtract(88, 'second').valueOf()); }); it('second: 888', () => { expect(momentjs(now).minus(888, 'second').valueOf()) - .to.be.equal(moment(now).subtract(888, 'second').valueOf()); + .toBe(moment(now).subtract(888, 'second').valueOf()); }); it('second: 8888', () => { expect(momentjs(now).minus(8888, 'second').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'second').valueOf()); + .toBe(moment(now).subtract(8888, 'second').valueOf()); }); it('millisecond: 1', () => { expect(momentjs(now).minus(1, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(1, 'millisecond').valueOf()); + .toBe(moment(now).subtract(1, 'millisecond').valueOf()); }); it('millisecond: 8', () => { expect(momentjs(now).minus(8, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(8, 'millisecond').valueOf()); + .toBe(moment(now).subtract(8, 'millisecond').valueOf()); }); it('millisecond: 88', () => { expect(momentjs(now).minus(88, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(88, 'millisecond').valueOf()); + .toBe(moment(now).subtract(88, 'millisecond').valueOf()); }); it('millisecond: 888', () => { expect(momentjs(now).minus(888, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(888, 'millisecond').valueOf()); + .toBe(moment(now).subtract(888, 'millisecond').valueOf()); }); it('millisecond: 8888', () => { expect(momentjs(now).minus(8888, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'millisecond').valueOf()); + .toBe(moment(now).subtract(8888, 'millisecond').valueOf()); }); it('week: 1', () => { expect(momentjs(now).minus(1, 'week').valueOf()) - .to.be.equal(moment(now).subtract(1, 'week').valueOf()); + .toBe(moment(now).subtract(1, 'week').valueOf()); }); it('week: 8', () => { expect(momentjs(now).minus(8, 'week').valueOf()) - .to.be.equal(moment(now).subtract(8, 'week').valueOf()); + .toBe(moment(now).subtract(8, 'week').valueOf()); }); it('week: 88', () => { expect(momentjs(now).minus(88, 'week').valueOf()) - .to.be.equal(moment(now).subtract(88, 'week').valueOf()); + .toBe(moment(now).subtract(88, 'week').valueOf()); }); it('week: 888', () => { expect(momentjs(now).minus(888, 'week').valueOf()) - .to.be.equal(moment(now).subtract(888, 'week').valueOf()); + .toBe(moment(now).subtract(888, 'week').valueOf()); }); it('week: 8888', () => { expect(momentjs(now).minus(8888, 'week').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'week').valueOf()); + .toBe(moment(now).subtract(8888, 'week').valueOf()); }); }); diff --git a/test/parse.spec.ts b/test/parse.spec.ts index f4db124..3ed90eb 100644 --- a/test/parse.spec.ts +++ b/test/parse.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import * as moment from 'moment'; import { Moment } from '../src'; @@ -8,41 +6,41 @@ const momentjs = (d?: number | string | Date) => new Moment({ date: d }); describe('parse', () => { it('now', () => { const now = new Date(); - expect(momentjs(now).valueOf()).to.be.equal(moment(now).valueOf()); + expect(momentjs(now).valueOf()).toBe(moment(now).valueOf()); }); it('format: 20130208', () => { const date = '20130208'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 2013-02-08', () => { const date = '2013-02-08'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 2013-02-08', () => { const date = '2013-02-08'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 2018-05-02 11:12:13', () => { const date = '2018-05-02 11:12:13'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 2018-05-02 11:12:13.998', () => { const date = '2018-05-02 11:12:13.998'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 2018-05-02T11:12:13Z', () => { const date = '2018-05-02T11:12:13Z'; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); it('format: 1546569450994', () => { const date = 1546569450994; - expect(momentjs(date).valueOf()).to.be.equal(moment(date).valueOf()); + expect(momentjs(date).valueOf()).toBe(moment(date).valueOf()); }); }); diff --git a/test/semver.spec.ts b/test/semver.spec.ts index 1720de6..71bf9cc 100644 --- a/test/semver.spec.ts +++ b/test/semver.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { Moment } from '../src'; const momentjs = (date: Date) => new Moment({ @@ -10,48 +8,48 @@ describe('semver', () => { it('year', () => { const date = new Date(); expect(momentjs(date).year()) - .to.be.equal(date.getFullYear()); + .toBe(date.getFullYear()); }); it('month', () => { const date = new Date(); expect(momentjs(date).month()) - .to.be.equal(date.getMonth()); + .toBe(date.getMonth()); }); it('day', () => { const date = new Date(); expect(momentjs(date).day()) - .to.be.equal(date.getDate()); + .toBe(date.getDate()); }); it('week', () => { const date = new Date(); expect(momentjs(date).week()) - .to.be.equal(date.getDay()); + .toBe(date.getDay()); }); it('hour', () => { const date = new Date(); expect(momentjs(date).hour()) - .to.be.equal(date.getHours()); + .toBe(date.getHours()); }); it('minute', () => { const date = new Date(); expect(momentjs(date).minute()) - .to.be.equal(date.getMinutes()); + .toBe(date.getMinutes()); }); it('second', () => { const date = new Date(); expect(momentjs(date).second()) - .to.be.equal(date.getSeconds()); + .toBe(date.getSeconds()); }); it('milliSecond', () => { const date = new Date(); expect(momentjs(date).milliSecond()) - .to.be.equal(date.getMilliseconds()); + .toBe(date.getMilliseconds()); }); }); diff --git a/test/set.spec.ts b/test/set.spec.ts index 6ca52fa..d0d9bf3 100644 --- a/test/set.spec.ts +++ b/test/set.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { Moment } from '../src'; const momentjs = () => new Moment(); @@ -8,48 +6,48 @@ describe('set', () => { it('year', () => { const mj = momentjs(); expect(mj.set('year', 2018).year()) - .to.be.equal(2018); + .toBe(2018); }); it('month', () => { const mj = momentjs(); expect(mj.set('month', 8).month()) - .to.be.equal(8); + .toBe(8); }); it('day', () => { const mj = momentjs(); expect(mj.set('day', 8).day()) - .to.be.equal(8); + .toBe(8); }); // it('week', () => { // const mj = momentjs(); // expect(mj.set('week', 6).week()) - // .to.be.equal(6); + // .toBe(6); // }); it('hour', () => { const mj = momentjs(); expect(mj.set('hour', 8).hour()) - .to.be.equal(8); + .toBe(8); }); it('minute', () => { const mj = momentjs(); expect(mj.set('minute', 8).minute()) - .to.be.equal(8); + .toBe(8); }); it('second', () => { const mj = momentjs(); expect(mj.set('second', 8).second()) - .to.be.equal(8); + .toBe(8); }); it('milliSecond', () => { const mj = momentjs(); expect(mj.set('millisecond', 8).milliSecond()) - .to.be.equal(8); + .toBe(8); }); }); diff --git a/test/startOf.spec.ts b/test/startOf.spec.ts index e584e71..65c4bba 100644 --- a/test/startOf.spec.ts +++ b/test/startOf.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { Moment } from '../src'; import { resolve } from '../src/utils'; @@ -13,7 +11,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('year').valueOf()) - .to.be.equal(+new Date(dates[0], 0, 1)); + .toBe(+new Date(dates[0], 0, 1)); }); it('month', () => { @@ -21,7 +19,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('month').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], 1)); + .toBe(+new Date(dates[0], dates[1], 1)); }); it('day', () => { @@ -29,7 +27,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('day').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2])); + .toBe(+new Date(dates[0], dates[1], dates[2])); }); it('week', () => { @@ -37,7 +35,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('week').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2] - resolve(date).week)); + .toBe(+new Date(dates[0], dates[1], dates[2] - resolve(date).week)); }); it('hour', () => { @@ -45,7 +43,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('hour').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3])); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3])); }); it('minute', () => { @@ -53,7 +51,7 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('minute').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4])); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4])); }); it('second', () => { @@ -61,6 +59,6 @@ describe('startOf', () => { const md = momentjs(date); const dates = md.toArray(); expect(md.startOf('second').valueOf()) - .to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5])); + .toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5])); }); }); diff --git a/test/subtract.spec.ts b/test/subtract.spec.ts index 39a5c5b..3230e75 100644 --- a/test/subtract.spec.ts +++ b/test/subtract.spec.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import * as moment from 'moment'; import { Moment } from '../src'; @@ -9,171 +8,171 @@ describe('subtract', () => { it('year', () => { expect(momentjs(now).subtract(5, 'year').valueOf()) - .to.be.equal(moment(now).subtract(5, 'year').valueOf()); + .toBe(moment(now).subtract(5, 'year').valueOf()); }); it('month: 3', () => { expect(momentjs(now).subtract(3, 'month').valueOf()) - .to.be.equal(moment(now).subtract(3, 'month').valueOf()); + .toBe(moment(now).subtract(3, 'month').valueOf()); }); it('month: 18', () => { expect(momentjs(now).subtract(18, 'month').valueOf()) - .to.be.equal(moment(now).subtract(18, 'month').valueOf()); + .toBe(moment(now).subtract(18, 'month').valueOf()); }); it('month: 128', () => { expect(momentjs(now).subtract(128, 'month').valueOf()) - .to.be.equal(moment(now).subtract(128, 'month').valueOf()); + .toBe(moment(now).subtract(128, 'month').valueOf()); }); it('day: 1', () => { expect(momentjs(now).subtract(1, 'day').valueOf()) - .to.be.equal(moment(now).subtract(1, 'day').valueOf()); + .toBe(moment(now).subtract(1, 'day').valueOf()); }); it('day: 8', () => { expect(momentjs(now).subtract(8, 'day').valueOf()) - .to.be.equal(moment(now).subtract(8, 'day').valueOf()); + .toBe(moment(now).subtract(8, 'day').valueOf()); }); it('day: 88', () => { expect(momentjs(now).subtract(88, 'day').valueOf()) - .to.be.equal(moment(now).subtract(88, 'day').valueOf()); + .toBe(moment(now).subtract(88, 'day').valueOf()); }); it('day: 888', () => { expect(momentjs(now).subtract(888, 'day').valueOf()) - .to.be.equal(moment(now).subtract(888, 'day').valueOf()); + .toBe(moment(now).subtract(888, 'day').valueOf()); }); it('day: 8888', () => { expect(momentjs(now).subtract(8888, 'day').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'day').valueOf()); + .toBe(moment(now).subtract(8888, 'day').valueOf()); }); it('hour: 1', () => { expect(momentjs(now).subtract(1, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(1, 'hour').valueOf()); + .toBe(moment(now).subtract(1, 'hour').valueOf()); }); it('hour: 8', () => { expect(momentjs(now).subtract(8, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(8, 'hour').valueOf()); + .toBe(moment(now).subtract(8, 'hour').valueOf()); }); it('hour: 88', () => { expect(momentjs(now).subtract(88, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(88, 'hour').valueOf()); + .toBe(moment(now).subtract(88, 'hour').valueOf()); }); it('hour: 888', () => { expect(momentjs(now).subtract(888, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(888, 'hour').valueOf()); + .toBe(moment(now).subtract(888, 'hour').valueOf()); }); it('hour: 8888', () => { expect(momentjs(now).subtract(8888, 'hour').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'hour').valueOf()); + .toBe(moment(now).subtract(8888, 'hour').valueOf()); }); it('minute: 1', () => { expect(momentjs(now).subtract(1, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(1, 'minute').valueOf()); + .toBe(moment(now).subtract(1, 'minute').valueOf()); }); it('minute: 8', () => { expect(momentjs(now).subtract(8, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(8, 'minute').valueOf()); + .toBe(moment(now).subtract(8, 'minute').valueOf()); }); it('minute: 88', () => { expect(momentjs(now).subtract(88, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(88, 'minute').valueOf()); + .toBe(moment(now).subtract(88, 'minute').valueOf()); }); it('minute: 888', () => { expect(momentjs(now).subtract(888, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(888, 'minute').valueOf()); + .toBe(moment(now).subtract(888, 'minute').valueOf()); }); it('minute: 8888', () => { expect(momentjs(now).subtract(8888, 'minute').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'minute').valueOf()); + .toBe(moment(now).subtract(8888, 'minute').valueOf()); }); it('second: 1', () => { expect(momentjs(now).subtract(1, 'second').valueOf()) - .to.be.equal(moment(now).subtract(1, 'second').valueOf()); + .toBe(moment(now).subtract(1, 'second').valueOf()); }); it('second: 8', () => { expect(momentjs(now).subtract(8, 'second').valueOf()) - .to.be.equal(moment(now).subtract(8, 'second').valueOf()); + .toBe(moment(now).subtract(8, 'second').valueOf()); }); it('second: 88', () => { expect(momentjs(now).subtract(88, 'second').valueOf()) - .to.be.equal(moment(now).subtract(88, 'second').valueOf()); + .toBe(moment(now).subtract(88, 'second').valueOf()); }); it('second: 888', () => { expect(momentjs(now).subtract(888, 'second').valueOf()) - .to.be.equal(moment(now).subtract(888, 'second').valueOf()); + .toBe(moment(now).subtract(888, 'second').valueOf()); }); it('second: 8888', () => { expect(momentjs(now).subtract(8888, 'second').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'second').valueOf()); + .toBe(moment(now).subtract(8888, 'second').valueOf()); }); it('millisecond: 1', () => { expect(momentjs(now).subtract(1, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(1, 'millisecond').valueOf()); + .toBe(moment(now).subtract(1, 'millisecond').valueOf()); }); it('millisecond: 8', () => { expect(momentjs(now).subtract(8, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(8, 'millisecond').valueOf()); + .toBe(moment(now).subtract(8, 'millisecond').valueOf()); }); it('millisecond: 88', () => { expect(momentjs(now).subtract(88, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(88, 'millisecond').valueOf()); + .toBe(moment(now).subtract(88, 'millisecond').valueOf()); }); it('millisecond: 888', () => { expect(momentjs(now).subtract(888, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(888, 'millisecond').valueOf()); + .toBe(moment(now).subtract(888, 'millisecond').valueOf()); }); it('millisecond: 8888', () => { expect(momentjs(now).subtract(8888, 'millisecond').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'millisecond').valueOf()); + .toBe(moment(now).subtract(8888, 'millisecond').valueOf()); }); it('week: 1', () => { expect(momentjs(now).subtract(1, 'week').valueOf()) - .to.be.equal(moment(now).subtract(1, 'week').valueOf()); + .toBe(moment(now).subtract(1, 'week').valueOf()); }); it('week: 8', () => { expect(momentjs(now).subtract(8, 'week').valueOf()) - .to.be.equal(moment(now).subtract(8, 'week').valueOf()); + .toBe(moment(now).subtract(8, 'week').valueOf()); }); it('week: 88', () => { expect(momentjs(now).subtract(88, 'week').valueOf()) - .to.be.equal(moment(now).subtract(88, 'week').valueOf()); + .toBe(moment(now).subtract(88, 'week').valueOf()); }); it('week: 888', () => { expect(momentjs(now).subtract(888, 'week').valueOf()) - .to.be.equal(moment(now).subtract(888, 'week').valueOf()); + .toBe(moment(now).subtract(888, 'week').valueOf()); }); it('week: 8888', () => { expect(momentjs(now).subtract(8888, 'week').valueOf()) - .to.be.equal(moment(now).subtract(8888, 'week').valueOf()); + .toBe(moment(now).subtract(8888, 'week').valueOf()); }); }); diff --git a/test/to.spec.ts b/test/to.spec.ts index e4eb20e..b1b93cc 100644 --- a/test/to.spec.ts +++ b/test/to.spec.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import * as moment from 'moment'; import { Moment } from '../src'; @@ -12,42 +10,42 @@ describe('set', () => { // it('toString', () => { // expect(mj.toString()) - // .to.be.equal(mo.toString()); + // .toBe(mo.toString()); // }); it('toString', () => { expect(mj.toString()) - .to.be.equal(today.toUTCString()); + .toBe(today.toUTCString()); }); it('toISOString', () => { expect(mj.toISOString()) - .to.be.equal(mo.toISOString()); + .toBe(mo.toISOString()); }); it('toJSON', () => { expect(mj.toJSON()) - .to.be.equal(mo.toJSON()); + .toBe(mo.toJSON()); }); it('toArray', () => { expect(mj.toArray()) - .to.be.deep.equal(mo.toArray()); + .toEqual(mo.toArray()); }); // it('toObject', () => { // expect(mj.toObject()) - // .to.be.deep.equal(mo.toObject()); + // .toEqual(mo.toObject()); // }); it('toObject', () => { expect(mj.toObject()) - .to.be.deep.equal(['year', 'month', 'day', 'hour', 'minute', 'second', 'milliSecond', 'week'] + .toEqual(['year', 'month', 'day', 'hour', 'minute', 'second', 'milliSecond', 'week'] .reduce((last, k) => (last[k] = mj[k].call(mj), last), {})); }); it('toDate', () => { expect(mj.toDate().toString()) - .to.be.equal(mo.toDate().toString()); + .toBe(mo.toDate().toString()); }); });