Ad
SyntaxError: Cannot Use Import Statement Outside A Module In JEST LWC
I am trying to test my first lightning web component using visual studio code as my IDE. As instructed I installed Node.js, npm and jest dependency. But I am getting this error
when trying to run the below code
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 in tests folder
// 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!');
});
});
Any input is appreciated
Ad
Answer
tsconfig.json
"compilerOptions": {
...
"allowJs": true
}
jest config
add
"transformIgnorePatterns": [
"node_modules/(?!lwc)"
]
remove
"testPathIgnorePatterns": [
"node_modules"
],
If that's not enough => jest --clearCache
Hope this helps
Ad
source: stackoverflow.com
Related Questions
- → Is It Possible To Use An External Database For User Data & Login Credentials With Shopify?
- → Change Database Source Depending on Login Credentials
- → JSON iteration in JAVA using jettison library
- → SyntaxError: Cannot use import statement outside a module in JEST LWC
- → Salesforce REST API query - URL limit
- → Regex to mask characters except first two digits in Java
- → How to make Multilevel Drop down navigation in wordpress theme?
- → laravel salesforce require_once?
- → Getting "INVALID_FIELD_FOR_INSERT_UPDATE" error message when try to update Salesforce Contact objet via Java(EnterpriseWSDL)
- → Infinite loop on ComponentWillMount ReactJS
- → how to get current date in MOMENT.JS Dynamic
- → Why i can't add Approval record row into the CR ticket
- → Pagination In Custom APEX REST Endpoint
Ad