vendredi 5 janvier 2018

How to format the date during unit-test with Ext JS format method?

I'm try to write a proper unit-test for method below. I'm trying to test the assertion within formatted date. Thusly trying to use Ext.Date.format method in assertion but it returns as failed.

How can i format the given and expected date to d.m.Y? (I'm not allowed to change method itself!)

dateAdd: function (aDate, aInterval, aValue) {
        var me = this;

        aDate = aDate || me.today();
        aInterval = aInterval || Ext.Date.DAY;
        aValue = aValue || 1;

        return Ext.Date.add(aDate, aInterval, aValue);
    },

and the test assertion;

t.describe('dateAdd() method', function(t) {
    t.it('should interval the given date', function(t) {
        t.expect(MyApp.dateAdd(new Date(Ext.Date.format('01.01.2018', 'd.m.Y')), Ext.Date.DAY, 1)).toBe('02.01.2018');
    });
});

// Result: 
// Failed assertion `expect(got).toBe(need)` at line 64 of 01-unit-tests.js
// Got  : "Invalid Date"
// Need : "02.01.2018"

Aucun commentaire:

Enregistrer un commentaire