Curious about TypeScript and Protractor:
I have a couple of basic helper functions stored in a shared.po.ts file within my Protractor suite. These functions are triggered by the third it() in my .spec file - meaning they are not immediately called upon running Protractor tests:
formattedDate(){
var MyDate = new Date();
var mth = ('0' + (MyDate.getMonth()+1));
var day = ('0' + MyDate.getDate());
var yr = MyDate.getFullYear();
return mth.slice(-2) +'/' + day.slice(-2) +'/' + yr;}
formattedDateTime(){
var MyDate = new Date();
var hrs = ('0' + MyDate.getHours()).slice(-2);
var mins =('0' + MyDate.getMinutes()).slice(-2);
var time = hrs +':'+mins;
return this.formattedDate() + ' ' + time;}
In my .spec file, I invoke the formattedDateTime() function like this:
let formattedDateTime = shared.formattedDate();
console.log(formattedDateTime);
What's puzzling is that when I run my test scripts, I instantly see "03/15/2019 10:15" displayed in the console. Unlike headless tests, I can clearly observe a browser window executing my scripts, and it's evident that the part of the .spec file containing the call to formattedDateTime() hasn't been executed yet.
Is there an explanation for this unexpected behavior? Appreciate any insights! Thank you!