jasmine mockDate 总是休息一个月

jasmine mockDate always one month off

我正在尝试使用 jasmine 的 mockDate() 编写时间相关的单元测试:

it("cookie_expiration() is 30 days out", function () {
    var baseTime = new Date(2016, 10, 1, 0, 0, 0, 0);
    jasmine.clock().mockDate(baseTime);
    console.info( new Date() );
    ...
});

我认为这正是他们在 the documentation 中显示的内容,但我在控制台中看到的是:Tue Nov 01 2016 00:00:00 GMT-0700 (PDT)

"devDependencies": {
  "jasmine": "^2.5.3",
  "karma": "^1.5.0",
  "karma-chrome-launcher": "^2.0.0",
  "karma-jasmine": "^1.1.0",
  "karma-junit-reporter": "^1.2.0",
  "karma-phantomjs-launcher": "^1.0.4"
}

根据Date | MDN

note that the month is 0-based

因此,这不是 jasminemockDate 的问题。是原生的Date.

这是显示现在是 11 月的片段:)

var baseTime = new Date(2016, 10, 1, 0, 0, 0, 0);
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

console.log("BaseTime month is " + monthNames[baseTime.getMonth()]);