Salesforce SyntaxError:无法在JEST LWC中的模块外部使用import语句
我正在尝试使用VisualStudio代码作为IDE测试我的第一个lightning web组件。按照指示,我安装了Node.js、npm和jest依赖项。但我得到了这个错误 当尝试运行以下代码时 driver_Registration.htmlSalesforce SyntaxError:无法在JEST LWC中的模块外部使用import语句,salesforce,lwc,Salesforce,Lwc,我正在尝试使用VisualStudio代码作为IDE测试我的第一个lightning web组件。按照指示,我安装了Node.js、npm和jest依赖项。但我得到了这个错误 当尝试运行以下代码时 driver_Registration.html <template> <div class="slds-m-around_medium"> <p>Hello, {person}!</p> </div> </template&
<template>
<div class="slds-m-around_medium">
<p>Hello, {person}!</p>
</div>
</template>
tests文件夹中的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
}
jest配置
加
除去
"testPathIgnorePatterns": [
"node_modules"
],
如果这还不够=>
开玩笑——clearCache
希望这有帮助
"transformIgnorePatterns": [
"node_modules/(?!lwc)"
]
"testPathIgnorePatterns": [
"node_modules"
],