我正在尝试使用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!');
});
});
任何输入表示赞赏
tsconfig.json
"compilerOptions": {
...
"allowJs": true
}
是配置
加
"transformIgnorePatterns": [
"node_modules/(?!lwc)"
]
去掉
"testPathIgnorePatterns": [
"node_modules"
],
如果那还不够=> jest --clearCache
希望这可以帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句