You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FAIL my-lit-element libs/my-lit-element/src/lib/my-lit-element.spec.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/POC/nx-lit-element-example/node_modules/lit/index.js:2
import "@lit/reactive-element";
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import { LitElement, css, html } from 'lit';
| ^
2 | import { customElement, property } from 'lit/decorators.js';
3 | @customElement('my-lit-element')
4 | export class MyLitElement extends LitElement {
at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (src/lib/my-lit-element.ts:1:1)
at Object.<anonymous> (src/lib/my-lit-element.spec.ts:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 4.135 s
Ran all test suites.
Expected Behavior
Test suite to be passed.
GitHub Repo
No response
Steps to Reproduce
Step 1: Create empty NX workspace and then add @nx/angular, @nx/js schematics.
Step 2: Create host angular app using below generator cmd.
Current Behavior
Facing below error when trying to run test cases for Lit Element through Jest in our NX monorepo. This happens even with node_modules transformed.
transformIgnorePatterns: ["node_modules/(?!(lit-html|lit-element|lit|@lit)/)"]
FAIL my-lit-element libs/my-lit-element/src/lib/my-lit-element.spec.ts
● Test suite failed to run
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 4.135 s
Ran all test suites.
Expected Behavior
Test suite to be passed.
GitHub Repo
No response
Steps to Reproduce
Step 1: Create empty NX workspace and then add @nx/angular, @nx/js schematics.
Step 2: Create host angular app using below generator cmd.
npx nx generate @nx/angular:application --directory=apps/angular-host --bundler=webpack --name=angular-host --routing=false --e2eTestRunner=none --style=scss
Step 3: Create sample js library using below generator cmd.
npx nx generate @nx/js:library --directory=libs/my-lit-element --importPath=@test --linter=eslint --name=my-lit-element --unitTestRunner=jest
Step 4: Run npm i lit --save and add below to respective files from scaffolding.
my-lit-element.ts file content
import { LitElement, css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
@CustomElement('my-lit-element')
export class MyLitElement extends LitElement {
public static override readonly styles = css
:host { display: block; padding: 16px; }
;@Property() name = 'My Lit Element!';
override render() {
return html
<p>This is the development zone of ${this.name}!</p>
;}
}
my-lit-element.spec.ts content
import { MyLitElement } from './my-lit-element';
import { html } from 'lit';
describe('MyViewModal ---', () => {
let testComponent: MyLitElement;
beforeEach(() => {
testComponent = new MyLitElement();
});
test('should create component', () => {
const actual = testComponent.render();
expect(actual).toBeDefined();
});
test('renders default message', () => {
const actual = testComponent.render();
expect(typeof actual).toBe(typeof html``);
});
});
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
Due to security concerns, not able to upload sample repo from my work machine.
The text was updated successfully, but these errors were encountered: