4

I'm writing unit tests for LWC using lwc-jest but when I try to follow the pattern documented in the Basic Lightning Component section of this documentation https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.unit_testing_using_jest_patterns then I get the warning:

[LWC warning]: If property value decorated with @api in [object:vm undefined (2)] is used in the template, the value 3 set manually may be overridden by the template, consider binding the property only in the template.

My HTML is just:

 <template>
    <lightning-input label="label"></lightning-input>
</template>

My JS is empty and my test is:

test('test', () => {
    let componentUnderTest = createElement('c-my-component', {
        is: MyComponent,
    });
    document.body.appendChild(componentUnderTest);

    return Promise.resolve().then(() => {
        const input= componentUnderTest.shadowRoot.querySelector('lightning-input');
    input.value = 'val';
    input.dispatchEvent(new CustomEvent('change'));
    }):
});

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.