那是因为您需要配置 karma 来加载,然后在需要时为它们提供服务;)
在您的 karma.conf.js 文件中,您应该已经定义了文件和/或模式,例如:
// list of files / patterns to load in the browser
files : [
{pattern: 'app/lib/angular.js', watched: true, included: true, served: true},
{pattern: 'app/lib/angular-*.js', watched: true, included: true, served: true},
{pattern: 'app/lib/**/*.js', watched: true, included: true, served: true},
{pattern: 'app/js/**/*.js', watched: true, included: true, served: true},
// add the line below with the correct path pattern for your case
{pattern: 'path/to/**/*.png', watched: false, included: false, served: true},
// important: notice that "included" must be false to avoid errors
// otherwise Karma will include them as scripts
{pattern: 'test/lib/**/*.js', watched: true, included: true, served: true},
{pattern: 'test/unit/**/*.js', watched: true, included: true, served: true},
],
// list of files to exclude
exclude: [
],
// ...
你可以看看这里了解更多信息:)
编辑:如果您使用 nodejs 网络服务器来运行您的应用程序,您可以将其添加到 karma.conf.js :
proxies: {
'/path/to/img/': 'http://localhost:8000/path/to/img/'
},
EDIT2 :如果您不使用或想使用另一台服务器,您可以定义本地代理,但由于 Karma 不提供对正在使用的端口的访问,动态地,如果 karma 在 9876(默认)以外的其他端口上启动,您仍然会得到那些烦人的 404 ......
proxies = {
'/images/': '/base/images/'
};
相关问题:https : //github.com/karma-runner/karma/issues/872