1

I created a component that has a required attribute of array type, ListCmp.cmp:

<aura:component>
  <aura:attribute name="items" type="Object[]" required="true" />

  <div>
    <ul class="slds-list_vertical>
      <aura:if isTrue="{!v.items.length}">
        <aura:iteration items="{!v.items}" var="item">
          <li class="slds-list__item">
           ...
          </li>
        </aura:iteration>
        <aura:set attribute="else">
          <span>empty</span>
        </aura:set>
      </aura:if>
    </ul>
  </div>
</aura:component>

and a parent component that I using the ListCmp component without providing the required attribute
<c:ListCmp />. Instead of getting an error I am getting the empty result rendered same as providing and empty array <c:ListCmp items="[]"/>

Edit

Jasmine test passes - correctly fails to create component without the required attribute:

it('does not renders', function(done) {
  $T.createComponent('c:ListCmp', {}, true)
    .then(function(component) {
      done.fail();
    })
    .catch(function(e) {
      expect(e).toBeTruthy();
      done();
    });
});
  • This could be a bug. If I use a parent/child combination with a required attribute in child and that I embed the parent in an app, the components fail to render if I don't provide the child attribute in parent. However using the components say on a Home Page, just works fine. You may like to reach out to SF support. – Jayant Das Feb 27 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.