Hi @Martin ,
Ok, I share my code.
pacekage.json
{
"name": "test-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "jest"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"bpmn-js": "^10.0.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.2",
"@angular/cli": "~14.2.2",
"@angular/compiler-cli": "^14.2.0",
"@babel/core": "^7.19.0",
"@babel/preset-env": "^7.19.0",
"@types/jest": "^28.1.8",
"jest": "^28.1.3",
"jest-canvas-mock": "^2.4.0",
"jest-preset-angular": "^12.1.0",
"typescript": "~4.7.2"
},
"jest": {
"preset": "jest-preset-angular",
"setupFilesAfterEnv": [
"<rootDir>/setup-jest.ts"
],
"transformIgnorePatterns": [
"/!node_modules\\/bpmn-js"
]
}
}
setup-jest.ts
import 'jest-preset-angular/setup-jest';
app.component.ts
import { Component, OnInit } from '@angular/core';
import BpmnModeler from 'bpmn-js/lib/Modeler';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
modeler: any;
constructor() {}
ngOnInit(): void {
this.modeler = new BpmnModeler();
}
}
app.component.spec.ts
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [AppComponent],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
});
Finally, run the npm run test command and test the code with jest, and the error is reported as follows:
> jest
FAIL src/app/app.component.spec.ts
● Test suite failed to run
TypeError: Cannot set property '$inject' of undefined
1 | import { Component, OnInit } from '@angular/core';
> 2 | import BpmnModeler from 'bpmn-js/lib/Modeler';
| ^
3 |
4 | @Component({
5 | selector: 'app-root',
at Object.<anonymous> (node_modules/diagram-js/lib/features/copy-paste/CopyPaste.js:165:18)
at Object.<anonymous> (node_modules/diagram-js/lib/features/copy-paste/index.js:6:1)
at Object.<anonymous> (node_modules/bpmn-js/lib/features/copy-paste/index.js:1:1)
at Object.<anonymous> (node_modules/bpmn-js/lib/features/replace/index.js:1:1)
at Object.<anonymous> (node_modules/bpmn-js/lib/features/popup-menu/index.js:2:1)
at Object.<anonymous> (node_modules/bpmn-js/lib/features/context-pad/index.js:6:1)
at Object.<anonymous> (node_modules/bpmn-js/lib/Modeler.js:20:1)
at Object.<anonymous> (src/app/app.component.ts:2:1)
at Object.<anonymous> (src/app/app.component.spec.ts:3:1)
at fulfilled (node_modules/tslib/tslib.js:115:62)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 173.984 s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-app@0.0.0 test: `jest`
npm ERR! Exit status 1