我使用moment.js
编写格式化日期的单元测试用例打字稿代码:
formatDate(date) {
date ? moment(date).format('DD-MM-YYYY') : '';
}
单元测试案例:
it('should return `Invalid date`', () => {
const date = '20111011000000Z';
expect(component.formatDate(date)).toBe('Invalid date');
});
我在运行此单元测试时收到以下警告,如何避免此警告。
WARN: 'Deprecation warning: value provided is not in a recognized RFC2822 or
ISO format. moment construction falls back to js Date(), which is not
reliable across all browsers and versions. Non RFC2822/ISO date forma
ts are discouraged and will be removed in an upcoming major release. Please
refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined,
_i: 20111011000000Z, _f: undefined, _strict: undefined, _locale: [object
Object]
undefined'
请您告诉我解决方案。