我正在尝试使用Visual Studio代码作为我的IDE测试我的第一个闪电Web组件。按照指示,我安装了Node.js,npm和jest依赖项。但是我遇到了这个错误
尝试运行以下代码时
driver_Registration.html
<template>
<div class="slds-m-around_medium">
<p>Hello, {person}!</p>
</div>
</template>
driver_Registration.js
import { LightningElement, api } from 'lwc';
export default class Driver_Registration extends LightningElement {
@api person = 'World';
}
测试文件夹中的hello.test.js
// hello.test.js
import { createElement } from 'lwc';
import Hello from 'c/driver_Registration';
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 pTag = element.shadowRoot.querySelector('p');
expect(pTag.textContent).toEqual('Hello, World!');
});
});
任何输入都值得赞赏
答案 0 :(得分:1)
tsconfig.json
"compilerOptions": {
...
"allowJs": true
}
最好的配置
添加
"transformIgnorePatterns": [
"node_modules/(?!lwc)"
]
删除
"testPathIgnorePatterns": [
"node_modules"
],
如果那还不够=> 开玩笑--clearCache
希望这会有所帮助