我正在测试使用传单的自定义地图组件。在测试组件传单'L'元素在窗口对象中不可用时。
在调试时,Leaflet js文件已正确加载,但未存储在obj窗口中。
我的angular.json文件
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [
"node_modules/leaflet/dist/leaflet.js",
"node_modules/leaflet-control-geocoder/dist/Control.Geocoder.js",
"node_modules/leaflet-routing-machine/dist/leaflet-routing-machine.js",
"node_modules/lrm-here/dist/lrm-here.js",
"node_modules/leaflet-rotatedmarker/leaflet.rotatedMarker.js"
],
"styles": [
"src/scss/styles.scss",
"node_modules/leaflet/dist/leaflet.css",
"node_modules/leaflet-routing-machine/dist/leaflet-routing-machine.css"
],
"assets": [
"src/assets",
"src/favicon.ico"
]
}
}
karma.ts文件
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: config.angularCli && config.angularCli.codeCoverage ? ['progress', 'coverage-istanbul'] : ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};