我遵循了安装node.js和jest的所有步骤。我有下面的LWC组件,并在按如下所述运行测试时出错,我尝试调试并更改根目录/文件夹,但我找不到根本原因并解决问题。有什么建议吗?
遇到错误:
● Test suite failed to run
**Cannot find module 'c/hello' from 'hello.test.js'**
1 | import { createElement } from 'lwc';
> 2 | import Hello from 'c/hello';
| ^
import { LightningElement } from 'lwc';
export default class Hello extends LightningElement {
greeting = 'World';
}
<template>
<lightning-card title="Hello" icon-name="custom:custom14">
<div class="slds-m-around_medium">
Hello, {greeting}!
</div>
<c-view-source source="lwc/hello" slot="footer">
Bind an HTML element to a component property.
</c-view-source>
</lightning-card>
</template>
hello.test.js
import {
createElement
} from 'lwc';
import Hello from 'c/hello';
describe('c-hello', () => {
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('displays greeting', () => {
// Create element
const element = createElement('c-hello', {
is: Hello
});
document.body.appendChild(element);
// Verify displayed greeting
const div = element.shadowRoot.querySelector('div');
expect(div.textContent).toBe('Hello, World!');
});
});