mardi 2 janvier 2018

What is proper unit-test assertion for ExtJS' Date() method?

I've started to write unit test with Siesta for an ExtJS made application and keep face with a failed test assertion. I've a method;

today: function () {
        return new Date();
    }

and trying this assertion;

describe('today() method', function(t) {
    t.it('should return new the date', function(t) {
        t.expect(MyApp.today(new Date())).toBe("Tue Jan 02, 2018"); //Today is Jan 02 2018 of course =) 
    });
});

but returns as;

    FAILED: Expect "Tue Jan 02 2018 13:27:29 GMT+0300 (+03)" to be "Tue Jan 02, 2018"
Failed assertion `expect(got).toBe(need)` at line 31 of 01-unit-tests/010_globals.js
Got  : "Tue Jan 02 2018 13:27:29 GMT+0300 (+03)"
Need : "Tue Jan 02, 2018"

So it fails because of time and GMT notation. What will be best assertion to test today method?

Aucun commentaire:

Enregistrer un commentaire