forcedotcom / LightningTestingService

Apache License 2.0
122 stars 35 forks source link

Setting DateTime attribute using $T.createComponent gives internal server error #83

Closed ahayes91 closed 4 years ago

ahayes91 commented 6 years ago

I'm trying to create a component in a lightning test with a required "DateTime" attribute, and getting an internal server error.

Example component "egAttributeTypes" has a "Date" example that works fine, but DateTime doesn't seem to work at all.

Steps to recreate: (Optional) Update jasmineTests.app to run only $Resource.jasmineExampleTests. Change "dateAtr" in egAttributeTypes to a DateTime type as per the following:

<aura:component >
    <aura:attribute name="stringAtr" type="String" />
    <aura:attribute name="integerAtr" type="Integer" />
    <aura:attribute name="booleanAtr" type="Boolean" />
    <aura:attribute name="dateAtr" type="DateTime" />
    <aura:attribute name="sobjectAtr" type="Sobject" />
    <aura:attribute name="accountAtr" type="Account" />
    <aura:attribute name="objectAtr" type="Object" />
    <aura:attribute name="objectAtrStringified" type="Object" />
    <aura:attribute name="AuraComponentAtr" type="Aura.Component[]" />
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <lightning:card >
        <aura:set attribute="title">
            Attribute Values
        </aura:set>
        <p aura:id="stringAtrAuraId">String: {!v.stringAtr}</p>
        <p>Integer: {!v.integerAtr}</p>
        <p>Boolean: {!v.booleanAtr}</p>
        <p>Date: {!v.dateAtr}</p>
        <p>Sobject: {!v.sobjectAtr.sObjectType}</p>
        <p>Account: {!v.accountAtr.sObjectType},{!v.accountAtr.Name}</p>
        <p>Object: {!v.objectAtrStringified}</p>
        <p aura:id="AuraComponentAtrId">Aura.Component[]: {!v.AuraComponentAtr}</p>
    </lightning:card>
</aura:component>

See results below.

screen shot 2018-08-14 at 11 01 11

It also fails in mochaTests.app.

I also tried different methods of setting the dateAtr in jasmineExampleTests.resource, like "2018-07-13T10:26:15.000Z" and "$A.localizationService.formatDate(new Date(), "MMMM DD YYYY, hh:mm:ss a");", but no luck.

There is a workaround if your DateTime attribute is not required on load of the component - in the spec you can remove setting the attribute from the "attributes" object and inside $T.createComponent, you can use component.set("v.dateAtr",new Date()); and it works fine. But if your attribute is required, this won't work.

esalman-sfdc commented 6 years ago

@ahayes91 this seems like a bug with one of the type convertors. As a workaround see if either passing datetime as a long ( e.g (new Date()).getTime()) or using a testWrapper component (which creates the component under test via its markup) gets you unblocked. I'll try posting back a work-item number for your future reference.

ahayes91 commented 6 years ago

Thanks @esalman-sfdc! Passing as a long works as a workaround - is there a reason why? Could you also explain how the testWrapper component works/throw me a link for reference?

hamzaahmed commented 6 years ago

We logged a bug for this issue (W-5377882) and it is scheduled to be fixed in Spring '19.