[英]Angular 2 test cannot load custom package
我正在按照官方的 angular2 指南对现有项目进行测试。
我使用自定义库downloadjs ,当我运行应用程序时它工作得很好。 但是在测试运行的情况下,我在控制台中收到错误消息:
"__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/downloadjs/download.js\n\tError: XHR error (404 Not Found) loading node_modules/downloadjs/download.js\n\tError loading node_modules/downloadjs/download.js as \"downloadjs\" from app/utilities/file-handler.utility.js"
我使用npm install downloadjs
来获取该工具。
file-handler.utility.js 如下:
import {Injectable} from "@angular/core";
import downloadjs=require("downloadjs");
@Injectable()
export class FileHandler{
public static download(fileToDownload: any) {
downloadjs(fileToDownload, "filename.txt" ,"text/plain");
}
}
我在同一个文件夹中创建了一个 defs.spec.ts 文件:
declare module 'downloadjs'{
function download(data:any, strFileName:string, strMimeType:string):void;
export = download;
}
并添加了 systemjs.config.js 的路径:
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'downloadjs': 'npm:downloadjs/download.js'
所以这在npm start.
运行得很好npm start.
但正如指南所述,在用这个创建 1st.spec.ts 之后:
describe('1st tests', () => {
it('true is true', () => expect(true).toBe(true));
});
这会引发我粘贴在顶部的错误。 感谢您的时间!
问题与 defs.spec.ts 位置有关。 我们决定使用现有的 angular 2 模板,在与它集成后,测试现在可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.