【发布时间】:2017-12-26 19:59:19
【问题描述】:
我对 Angular 2 应用程序进行了一些测试,这些应用程序在 Firefox 中运行时通过但在 PhantomJS 中失败。在测试中,我正在检查日期是否设置正确。我以“2017-07-20T14:20”的形式输入本地 iso 日期字符串。日期部分设置正确,但时间已关闭。我在山区时区(-6:00 UTC)运行测试,所以时间是 08:20。是否有我可能缺少的垫片或设置配置。
这里有一些代码:
在我的 customDate 类文件中
public startTime: string;
public setDate(date: string) {
let date:Date = new Date(date);
this.startTime = date.getHours() + ':';
if (date.getMinutes() < 10) {
this.startTime += date.getMinutes() + '0';
} else {
this.startTime += date.getMinues();
}
}
在我的测试文件中
it('should pass') {
let testDate = new customDate();
testDate.setDate('2017-07-20T14:20');
expect(testDate.startTime).toBe('14:00'); <-- this is failing it's comeing through as ('8:00')
}
【问题讨论】:
-
我认为您输入的时间是UTC,除非您使用time offset
标签: angular jasmine phantomjs karma-runner