我有一个用Jasmine测试运行器编写的测试:
it("Expect 'due date' to be 14 days from today", function () {
var dateNow = new Date();
scope.dateOfService(dateNow);
expect(scope.DueDate == new Date(dateNow.setDate(dateNow.getDate() + 14))).toBeTruthy();
});
但是这总是返回false?我有什么不对的吗?
要调试'我也跑了:
expect(scope.DueDate).toBe(new Date(dateNow.setDate(dateNow.getDate() + 14)));
然后返回:
Expected Date(Tue Nov 11 2014 08:20:23 GMT+0000 (GMT Standard Time)) to be Date(Tue Nov 11 2014 08:20:23 GMT+0000 (GMT Standard Time))
答案 0 :(得分:3)
var dateNow = new Date();
scope.dateOfService(dateNow);
var dateReturned = new Date(scope.DueDate);
var dateAdd = new Date(dateNow.setDate(dateNow.getDate() + 14));
expect(dateReturned).toEqual(dateAdd);
重点是确保它是.toEqual
而不是.toBe
。