我有一个简单的组件可以显示PrimeNG的时间表。仅此而已,仅组件中的数据和模板中的计划。还有一个单元测试规范(我使用Karma和Jasmine),只有一个测试-“应该创建”,由cli生成。我在ScheduleModule
的导入中有TestBed
。问题是单元测试失败并显示消息
ReferenceError: jQuery is not defined
at Schedule.push../node_modules/primeng/components/schedule/schedule.js.Schedule.initialize (http://localhost:9876/_karma_webpack_/webpack:/node_modules/primeng/components/schedule/schedule.js:225:1)
at Schedule.push../node_modules/primeng/components/schedule/schedule.js.Schedule.ngAfterViewChecked (http://localhost:9876/_karma_webpack_/webpack:/node_modules/primeng/components/schedule/schedule.js:208:1)
at callProviderLifecycles (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:9362:1)
at callElementProvidersLifecycles (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:9333:1)
at callLifecycleHooksChildrenFirst (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:9323:1)
at checkAndUpdateView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:10259:1)
at callViewAction (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:10491:1)
at execComponentViewsAction (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:10433:1)
at checkAndUpdateView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:10256:1)
at callWithDebugContext (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm5/core.js:11143:1)
我假设我应该在单元测试配置中的某个地方添加jQuery。将import 'chart.js';
添加到test.ts
有助于解决PrimeNG图表的类似问题。问题是,我应该在哪里放置什么,以便Karma知道jQuery在哪里?
来自package.json
的依赖项:
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"chart.js": "^2.7.2",
"core-js": "^2.5.4",
"fullcalendar": "^3.9.0",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"primeicons": "^1.0.0-beta.9",
"primeng": "^6.0.0",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.2",
"@angular-devkit/build-angular": "~0.6.3",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.3",
"@angular/language-service": "^6.0.2",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}