Closed AllanOricil closed 2 years ago
My real implementation works as expected. I can't just write jest test for it :/
If I remove these lines
import BaseComponent from 'c/baseComponent';
jest.mock('c/baseComponent');
createElement does not throw the error. But I can't remove those lines because I have to mock the baseClass, right?
Ok, no need for that. Then to avoid repeating tests across all children I will isolate the common ones in a separate module and then import on each test.
Description
I have a quick action built with LWC that has to be used in multiple Objects. Since quick actions don't support passing parameters I have to create one Quick Action for each Object. Each quick action will share the same UI, the only difference is the Data that each display. To implement this and avoid code repetition, specifically to avoid having multiple dummy .html files on each one of the lwc components that are specific to each Object, I'm using inhertance, instead of composition. The base class takes care of rendering the UI and controlling the main logic of the component, and each child class provides data, as each object has its own way of fetching the data (SOQL queries vary).`
When I tried to write tests for the Child component, I got the following error message:
From the error message I concluded that this library does not allow us to Test child classes. I think you are not considering that if I extend a base class that is extending "LightningElement", this child class is also a "LightningElement". So it should be accepted by the "createElement" method.
Steps to Reproduce
To exemplify this, take a look at a simple version of this component
baseComponent.html
baseComponent.js
baseComponent.js-meta.xml
childComponent.js
childComponent.js-meta.xml
childComponent.test.js
I could have used Composition, but I would end up with lots of dummy .html, one for each component, that would be exactly the same, thus requiring code repetition.
Expected Results
Child/Sub classes that exnteds a Parent/Base class that extends "LightningElement" should be allowed on "createElement" method.
Actual Results
Version
Possible Solution
The problem is here, I think:
Additional context/Screenshots