我有以下 Jasmine 单元测试:
describe('getAlertsByUserId', function () {
it('should get alerts from api/Alert/bob when the username is bob', inject(function (AlertService, $httpBackend) {
$httpBackend.when('GET', 'api/Alert/bob').respond(mockAlerts);
var alerts = AlertService.getAlertsByUserId('bob');
$httpBackend.flush();
expect(alerts).toEqual(mockAlerts);
}));
});
mockAlerts 定义如下:
[{
date: new Date(2013, 5, 25),
description: '',
alertType: 'type1',
productDescription: 'product',
pack: 12,
size: 16,
unitOfMeasure: 'OZ',
category: 'cat1',
stage: 'C',
status: 'I'
}]
当我在 Karma 中执行测试时,我得到“预期 [{date:...etc }] 等于 [{date:...etc}]。我已验证这两个对象是相同的(属性/值)。我尝试删除 Date 对象,但无济于事。有人吗?