I am working on an lwc-oss project and found reference to lightning-base-components npm package in a salesforce blog post.
We have started utilizing this package but now when trying to write jest tests around our custom components we are running into errors trying resolve modules that are not exposed inside of the package.
Cannot find module 'lightning/primitiveIcon' from 'node_modules/lightning-base-components/src/lightning/buttonIcon/buttonIcon.html'
I've added the following to our jest config:
transformIgnorePatterns: [
"/node_modules/(?!lightning-base-components)",
],
Any assistance or direction on this would be great.
Example Below:
Here is the basic component and test I am working with. If I remove the lightning-card component from the html it passes. When adding the component it fails.
basic.html
<template>
<lightning-card>
<h3 class="slds-text-heading_small slds-text-title_bold">
<a title={title}>{title}</a>
</h3>
</lightning-card>
</template>
basic.js
import {LightningElement} from "lwc";
export default class basic extends LightningElement {
title;
}
basic.test.js
import { createElement } from "lwc";
import Popover from "c/basic";
import { afterEach, beforeEach, describe, it, jest } from "@jest/globals";
describe("ccm-popover", () => {
const title = 'this is a title';
beforeEach(() => {
document.body.appendChild(element);
});
afterEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});
const element = createElement("ccm-basic", {
is: Popover
});
element.title = title;
it("title anchor has value of title attribute", () => {
const titleAnchor = element.shadowRoot.querySelector("h3 a");
expect(titleAnchor).toHaveProperty("title", title);
});
});