I've a function which is simply interval the given date;
dateAdd: function (theDate, theInterval, theValue) {
var me = this;
theDate = theDate || me.today();
theInterval = theInterval || Ext.Date.DAY;
theValue = theValue || 1;
return Ext.Date.add(theDate, theInterval, theValue);
},
but it gives error! Even when i gave exactly the same date/time/timezone value. Why could i getting this error?
t.describe('dateAdd() method', function(t) {
t.it('should interval the given date', function(t) {
t.expect(MyApp.Globals.dateAdd(new Date('01.02.2018'), Ext.Date.DAY, 1)).toBe('Wed Jan 03 2018 00:00:00 GMT+0300 (+03)');
});
});
Launching test suite, OS: MacOS, browser: Chrome 63.0.3239.132
dateAdd() method
should interval the given date
fail 1 - Expect "Wed Jan 03 2018 00:00:00 GMT+0300 (+03)" to be "Wed Jan 03 2018 00:00:00 GMT+0300 (+03)"
Failed assertion `expect(got).toBe(need)` at line 69 of 01-unit-tests/010_globals.t.js
Got : "Wed Jan 03 2018 00:00:00 GMT+0300 (+03)"
Need : "Wed Jan 03 2018 00:00:00 GMT+0300 (+03)"
[FAIL] 01-unit-tests/010_globals.t.js
Ok. sorry to miss that =| but it's not match with a new date method as well;
t.describe('dateAdd() method', function(t) {
t.it('should interval the given date', function(t) {
t.expect(MyApp.Globals.dateAdd(new Date('01.01.2018'),Ext.Date.DAY, 1)).toBe(new Date('01.02.2018'));
});
});
Expect "Tue Jan 02 2018 00:00:00 GMT+0300 (+03)" to be "Tue Jan 02 2018 00:00:00 GMT+0300 (+03)"
Failed assertion `expect(got).toBe(need)` at line 24 of 01-unit-tests/010_globals.t.js
Got : "Tue Jan 02 2018 00:00:00 GMT+0300 (+03)"
Need : "Tue Jan 02 2018 00:00:00 GMT+0300 (+03)"
Actually, this is by design (following jasmine conventions). "toBe" is equivalent of ===, which will always be `false` for different object instances ({} === {} - false). Since Date is an object it fails.
You want "toEqual()" instead.
I'll update the docs, to mention the Date explicitly.