I am writing a tests for my LWC component using jest-cucumber. This is my test:
defineFeature(feature, test => {
beforeEach(() => {
element = createElement('c-myLwcElement', {
is: myLwcElement,
});
})
});
but createElement
(imported from 'lwc') is not working as expected. The element is created but connectedCallback
is not called. In contrast, here is my generated jest test:
describe('c-myLwcElement', () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});
it('TODO: test case generated by CLI command, please fill in test logic', async () => {
// Arrange
const element = createElement('c-myLwcElement', {
is: Aggriddatatablev2qed,
});
element.objectApiName = 'Asset';
// Act
// document.body.appendChild(element);
// Assert
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});
Here, connectedCallback
is called correctly for my component.
What is wrong with my setup in my jest-cucumber
test?