使用Mocha,Chai和Moment.js假定以下简化的测试用例:
describe( 'test', () => {
it( 'should not show that many details', async () => {
const res = { d: null };
Assert.equal( res, { d: Moment( '2018-12-03' ) });
});
});
目前,这产生了非常详尽的报告,显示了Moment.js实例的所有内部结构。
1) test
should not show that many details:
AssertionError [ERR_ASSERTION]: { d: null } == { d: moment("2018-12-03T00:00:00.000") }
+ expected - actual
{
- "d": [null]
+ "d": {
+ "_d": [Date: 2018-12-02T23:00:00.000Z]
+ "_f": "YYYY-MM-DD"
+ "_i": "2018-12-03"
+ "_isAMomentObject": true
+ "_isUTC": false
+ "_isValid": true
+ "_locale": {
+ "_abbr": "en"
+ "_calendar": {
+ "lastDay": "[Yesterday at] LT"
+ "lastWeek": "[Last] dddd [at] LT"
+ "nextDay": "[Tomorrow at] LT"
+ "nextWeek": "dddd [at] LT"
+ "sameDay": "[Today at] LT"
+ "sameElse": "L"
+ }
+ "_config": {
+ "abbr": "en"
+ "calendar": {
+ "lastDay": "[Yesterday at] LT"
+ "lastWeek": "[Last] dddd [at] LT"
+ "nextDay": "[Tomorrow at] LT"
+ "nextWeek": "dddd [at] LT"
+ "sameDay": "[Today at] LT"
+ "sameElse": "L"
+ }
+ "dayOfMonthOrdinalParse": /\d{1,2}(th|st|nd|rd)/
+ "invalidDate": "Invalid date"
+ "longDateFormat": {
+ "L": "MM/DD/YYYY"
+ "LL": "MMMM D, YYYY"
+ "LLL": "MMMM D, YYYY h:mm A"
+ "LLLL": "dddd, MMMM D, YYYY h:mm A"
+ "LT": "h:mm A"
+ "LTS": "h:mm:ss A"
+ }
+ "meridiemParse": /[ap]\.?m?\.?/i
+ "months": [
+ "January"
+ "February"
+ "March"
+ "April"
+ "May"
+ "June"
+ "July"
+ "August"
+ "September"
+ "October"
+ "November"
+ "December"
+ ]
+ "monthsShort": [
+ "Jan"
+ "Feb"
+ "Mar"
+ "Apr"
+ "May"
+ "Jun"
+ "Jul"
+ "Aug"
+ "Sep"
+ "Oct"
+ "Nov"
+ "Dec"
+ ]
+ "ordinal": [Function]
+ "relativeTime": {
+ "M": "a month"
+ "MM": "%d months"
+ "d": "a day"
+ "dd": "%d days"
+ "future": "in %s"
+ "h": "an hour"
+ "hh": "%d hours"
+ "m": "a minute"
+ "mm": "%d minutes"
+ "past": "%s ago"
+ "s": "a few seconds"
+ "ss": "%d seconds"
+ "y": "a year"
+ "yy": "%d years"
+ }
+ "week": {
+ "dow": 0
+ "doy": 6
+ }
+ "weekdays": [
+ "Sunday"
+ "Monday"
+ "Tuesday"
+ "Wednesday"
+ "Thursday"
+ "Friday"
+ "Saturday"
+ ]
+ "weekdaysMin": [
+ "Su"
+ "Mo"
+ "Tu"
+ "We"
+ "Th"
+ "Fr"
+ "Sa"
+ ]
+ "weekdaysShort": [
+ "Sun"
+ "Mon"
+ "Tue"
+ "Wed"
+ "Thu"
+ "Fri"
+ "Sat"
+ ]
+ }
+ "_dayOfMonthOrdinalParse": /\d{1,2}(th|st|nd|rd)/
+ "_dayOfMonthOrdinalParseLenient": /\d{1,2}(th|st|nd|rd)|\d{1,2}/
+ "_invalidDate": "Invalid date"
+ "_longDateFormat": {
+ "L": "MM/DD/YYYY"
+ "LL": "MMMM D, YYYY"
+ "LLL": "MMMM D, YYYY h:mm A"
+ "LLLL": "dddd, MMMM D, YYYY h:mm A"
+ "LT": "h:mm A"
+ "LTS": "h:mm:ss A"
+ }
+ "_meridiemParse": /[ap]\.?m?\.?/i
+ "_months": [
+ "January"
+ "February"
+ "March"
+ "April"
+ "May"
+ "June"
+ "July"
+ "August"
+ "September"
+ "October"
+ "November"
+ "December"
+ ]
+ "_monthsShort": [
+ "Jan"
+ "Feb"
+ "Mar"
+ "Apr"
+ "May"
+ "Jun"
+ "Jul"
+ "Aug"
+ "Sep"
+ "Oct"
+ "Nov"
+ "Dec"
+ ]
+ "_relativeTime": {
+ "M": "a month"
+ "MM": "%d months"
+ "d": "a day"
+ "dd": "%d days"
+ "future": "in %s"
+ "h": "an hour"
+ "hh": "%d hours"
+ "m": "a minute"
+ "mm": "%d minutes"
+ "past": "%s ago"
+ "s": "a few seconds"
+ "ss": "%d seconds"
+ "y": "a year"
+ "yy": "%d years"
+ }
+ "_week": {
+ "dow": 0
+ "doy": 6
+ }
+ "_weekdays": [
+ "Sunday"
+ "Monday"
+ "Tuesday"
+ "Wednesday"
+ "Thursday"
+ "Friday"
+ "Saturday"
+ ]
+ "_weekdaysMin": [
+ "Su"
+ "Mo"
+ "Tu"
+ "We"
+ "Th"
+ "Fr"
+ "Sa"
+ ]
+ "_weekdaysShort": [
+ "Sun"
+ "Mon"
+ "Tue"
+ "Wed"
+ "Thu"
+ "Fri"
+ "Sat"
+ ]
+ "ordinal": [Function]
+ }
+ "_pf": {
+ "charsLeftOver": 0
+ "empty": false
+ "invalidFormat": false
+ "invalidMonth": [null]
+ "iso": true
+ "meridiem": [undefined]
+ "nullInput": false
+ "overflow": -1
+ "parsedDateParts": [
+ 2018
+ 11
+ 3
+ ]
+ "rfc2822": false
+ "unusedInput": []
+ "unusedTokens": []
+ "userInvalidated": false
+ "weekdayMismatch": false
+ }
+ }
}
如何将输出缩短为.toString()
或类似名称提供的内容?
我本来以为有某种我可以覆盖的序列化函数,但是到目前为止还不能。