在deepEqual中奇怪的新date
我有这个代码
var assert = require('assert'); describe('date', function() { it('deep equal', function() { assert.deepEqual({date: ''}, {date:new Date()}); }); });
当我用摩卡进行testing时,我得到了这个
AssertionError: { date: '' } deepEqual { date: 2017-03-08T21:58:45.767Z } + expected - actual { - "date": "" + "date": [Date: 2017-03-08T21:58:45.767Z] } at Context.<anonymous> (test/test_date.js:5:12)
为什么deepEqual生成的date格式为[Date: 2017-03-08T21:58:45.767Z]
而不是这种格式2017-03-08T21:58:45.767Z
?
为什么生成的date在括号[Date: ...]
?
在我看来,这是testing套件向您显示对象是Date
类的实例的方式。 如果仅仅是2017-03-08T21:58:45.767Z
,你就不会得到这个信息,并且在更复杂的情况下可能会更难debugging。
在第一行中,
AssertionError: { date: '' } deepEqual { date: 2017-03-08T21:58:45.767Z }
它显示toISOString()
表示,但是这可能会引起误解,因为date
的值不是该string。 该值是一个Date
对象,所以在差异中它清楚。