gpt4 book ai didi

Angular2 测试 : 'Unhandled Promise rejection:' , 'Failed to load strategyTables.html'

转载 作者:行者123 更新时间:2023-11-28 20:14:05 28 4
gpt4 key购买 nike

我在使用 templateUrl 测试组件时遇到了这个错误。我想知道它是否是 webpasck'test 的问题。我不知道如何修复它。谢谢提前!

错误:'未处理的 promise 拒绝:','无法加载 strategyTables.html',';区域:','ProxyZone',';任务:', 'Promise.then', ';值:','无法加载 strategyTables.html',未定义错误:错误{originalStack:'错误:未捕获( promise ):无法加载 strategyTables.html

//karma.config.js
// Karma configuration

var webpackConfig = require('./webpack.test');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '.',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
{pattern: './karma-shim.js', watched: false}
],

// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./karma-shim.js': ['webpack']
},
webpack: webpackConfig,
plugins:[
'karma-jasmine',
'karma-chrome-launcher',
require("karma-webpack")
],
proxies:{
//http://localhost:3000/#/pages/strategys/strategytables
"/app/": "base/src/app"
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}

//karma-shim,js
Error.stackTraceLimit = Infinity;

require('reflect-metadata');
require('zone.js/dist/zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');


var appContext = require.context('./src',true,/\.spec\.ts/);
appContext.keys().forEach(appContext);


var testing = require('@angular/core/testing');
var testingBrowser = require('@angular/platform-browser-dynamic/testing');
testing.TestBed.initTestEnvironment(testingBrowser.
BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting());

//webpack.test.js
module.exports = {
devtool: 'cheap-module-eval-source-map',
resolve: {
extensions: ['.ts','.js']
},

entry: {
},

module: {
loaders: [
//��.ts��β���ļ�ʹ�� TypeScript loader
{test: /.ts$/,loader: 'awesome-typescript-loader'},
{
test:/\.html$/,
loader: 'html'
},
{
test:/\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null'
},
{
test:/\.css$/,
loader: 'null'
}
]
}

}

最佳答案

在使用 templateURL 测试组件并将原始 html 分配给它时,我遇到了同样的 Unhandled Promise Rejection 错误。我相信这是因为它试图加载一个不存在的 html 文件。使用带有原始 html 的 template 解决了这个问题。

我认为所有这些错误都意味着找不到指定的 html 文件,因此请确保路​​径正确并且所需的 html 文件位于正确的位置。

关于Angular2 测试 : 'Unhandled Promise rejection:' , 'Failed to load strategyTables.html',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44096274/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com